美文网首页
Nginx 高级配置

Nginx 高级配置

作者: Alexander_Zz | 来源:发表于2019-03-19 14:58 被阅读0次

状态页

  • 编译安装情况下需要,--with-http_stub_status_module 开启状态页功能
location  /nginx_status {
  stub_status;
  allow 127.0.0.1;
  deny all;
  }

第三方模块安装

~]# yum install -y git
~]# git clone https://github.com/openresty/echo-nginx-module.git
~]# cd nginx-1.12.2
~]#  ./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_mofule \
--with-http_perl_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/echo-nginx-mofule
~]# make && make install

~]# /apps/nginx/sbin/nginx -t
 nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok 
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
# 确认通过语法检测

~]# /apps/nginx/sbin/nginx -s stop
~]# /apps/nginx/sbin/nginx
# 重启并访问测试

连接数

  • event 段配置
events {
  work_connections 100000;
  use epool;
  accept_mutex  on;  # 优化同一时刻只有一个请求而避免多个睡眠进程被唤醒,全群唤醒亦称为"惊群",默认为 off
  multi_accept  on;   #  Nginx服务器的每个工作进程可以同时接受多个新的网络连接,但是需要在配置文件中 配置,此指令默认为关闭
}

服务器上需要 ulimit -r 数量增加以配合使用

  • http 段配置
http {
  sendfile    on;  # 建议开启
  keepalive_timeout   65;  # 建议开启
  gzip   on:   # 支持压缩,建议开启,静态服务器最好打开,节省资源
}

静态页面启用压缩功能

  • 依赖模块 http_gzip_module
  • 配置指令
gzip on | off;
# 启用或禁用 gzip 压缩,默认关闭
gzip_comp_level LEVEL;
# 压缩比由低到高用 1-9 表示,默认为1
gzip_disable "MSIE [1-6]\.";
# 禁用 IE6 gzip 功能
gzip_min_length 1k;
# gzip 压缩的最小文件,小于设置值的文件将不会压缩
gzip_http_version 1.0|1.1;
# 启用压缩功能时,协议的最小版本,默认 HTTP/1.1
gzip_buffers NUMBER size;
# 指定 Nginx 服务器需要向服务器申请的缓存空间的个数*大小,默认32 4k|16 8k
gzip_types mime-type ...;
# 指明仅对哪些类型的资源执行压缩操作;默认为 gzip_type text/html,不用显示指定,否则出错
gzip_vary on | off;
# 如果启用压缩,是否在相应报文首部插入"Vary: Accept-Encoding"

相关文章

网友评论

      本文标题:Nginx 高级配置

      本文链接:https://www.haomeiwen.com/subject/qjjjmqtx.html