2核1G3M服务器88一季度

腾讯云,阿里云百度云等 折扣价→点我←

Discuz!论坛网站Nginx环境配置模块与应用详解 discuz 教程

游客1 游客组

前言
Nginx是由俄罗斯软件工程师Igor Sysoev开发的一个高性能的HTTP和反向代理服务器,具备IMAP/POP3和SMTP服务器功能。Nginx最大的特点是对高并发的支持和高效的负载均衡,在高并发的需求场景下,是Apache服务器不错的替代品。目前,包括新浪、腾讯等知名网站都已使用Nginx作为Web应用服务器。本文带来的是Nginx配置与应用详解。
基础特性
基本功能
静态资源的web服务器,能缓存打开的文件描述符
反向代理服务器,缓存、负载均衡
支持FastCGI
模块化,非DSO机制,过滤器gzip,SSI和图像大小调整等
支持SSL
扩展功能
基于名称和IP做虚拟主机
支持keepalive
支持平滑配置更新或程序版本升级
定制访问日志,支持使用日志缓存以提高性能
支持url rewrite
支持路径别名
支持基于IP及用户的认证
支持速率限制,并发限制等
基本架构
一个master, 生成一个或多个worker
事件驱动:kqueue, epoll, /dev/poll
消息通知:select, poll, rt signals
支持sendfile, sendfile64
文件AIO
支持mmap
模块类别
核心模块
标准http模块
可选的http模块
邮件模块
第三方扩展模块
基本配置
虚拟主机
http://p1.pstatp.com/large/12df0001a964bffed3aa
虚拟主机基本配置完成,当然虚拟主机里也可以有很多参数的,下文会提及到
访问控制
基于用户
认证文件由htpasswd命令创建
http://p3.pstatp.com/large/128200046e8650d84e32
访问测试
http://p9.pstatp.com/large/12df0001a96367cf155b
基于IP
http://p3.pstatp.com/large/12db00005e5dcfba6477
重启服务后访问测试
http://p1.pstatp.com/large/12da000035bcf48345a5
压缩功能
nginx将响应报文发送至客户端之前可以启用压缩功能,这能够有效地节约带宽,并提高响应至客户
端的速度。通常编译nginx默认会附带gzip压缩的功能,因此,可以直接启用之。
http://p1.pstatp.com/large/12da000035bea646c554
未压缩访问测试
http://p3.pstatp.com/large/12da000035bf6603a520
http://p3.pstatp.com/large/12db00005e5e9be9d010
重启服务,压缩后测试
http://p3.pstatp.com/large/12df0001a966683aeb46
压缩成功
防盗链
(1) 定义合规的引用
http://p3.pstatp.com/large/128200046e875efca740
(2) 拒绝不合规的引用
http://p9.pstatp.com/large/12df0001a96515daade9
http://p3.pstatp.com/large/12df0001a96845f9ad89
http://p3.pstatp.com/large/12df0001a967f02ed199
访问测试
http://p3.pstatp.com/large/128200046e88c72c6ce4
http://p1.pstatp.com/large/12df0001a9690b1f986c
反向代理
Nginx通过proxy模块实现反向代理功能。在作为web反向代理服务器时,nginx负责接收客户请求,并能够根据URI、客户端参数或其它的处理逻辑将用户请求调度至上游服务器上(upstream server)。
nginx在实现反向代理功能时的最重要指令为proxy_pass,它能够将location定义的某URI代理至指定的上游服务器(组)上。如下面的示例中,location的/uri将被替换为上游服务器上的/newuri。
http://p3.pstatp.com/large/12da000035c29de11ad8
http://p3.pstatp.com/large/128200046e899be69e8b
缓存
nginx做为反向代理时,能够将来自上游服务器的响应缓存至本地,并在后续的客户端请求同样内容时
直接从本地构造响应报文。
http://p3.pstatp.com/large/12df0001a96ad2fa246e
http://p1.pstatp.com/large/12df0001a96be3bb9d6a
缓存前请求时间
http://p1.pstatp.com/large/12de00006686890223ad
缓存后请求时间
http://p3.pstatp.com/large/12da000035c454bba663
此时缓存目录应该有缓存文件生成
http://p3.pstatp.com/large/128200046e8ae78ae5bd
负载均衡
nginx可利用自身的upstream模块实现,upstream模块的负载均衡算法主要有三种,轮调(round-robin)、ip哈希(ip_hash)和最少连接(least_conn)三种。
http://p3.pstatp.com/large/12db00005e5f14ceba92
http://p3.pstatp.com/large/12de0000668855124a3c
http://p3.pstatp.com/large/12da000035c325e114e8
如此便可实现简单的负载均衡功能

站长窝论坛版权声明 1、本帖标题:Discuz!论坛网站Nginx环境配置模块与应用详解
2、论坛网址:站长窝论坛
3、站长窝论坛的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
4、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
5、站长窝论坛一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本帖由游客1在站长窝论坛《程序综合区》版块原创发布, 转载请注明出处!
评论
最新回复 (0)
返回
发新帖