nginx.conf优化配置

user www; #运行的用户
worker_processes auto; #生成worker进程数
worker_rlimit_nofile 1048576;

pid /usr/local/nginx/run/nginx.pid;
google_perftools_profiles /usr/local/nginx/tmp/tcmalloc/tcmalloc;

events {
  use epoll; #linux下使用epoll,bsd下使用kqueue
  worker_connections 65535; #一个worker可以打开的最大连接数
  multi_accept on; #收到一个新连接通知后接受尽可能多的连接
}

http {
  include mime.types; #支持mime类型
  include proxy.conf; #代理参数设置
  include gzip.conf; #压缩设置

  default_type application/octet-stream;
  charset UTF-8;
  index index.html index.htm index.php; #索引文件

  error_log  /usr/local/nginx/logs/error.log crit;  #日志和日记级别
  access_log off;   log_format main
'$remote_addr - $remote_user [$time_local] "$request" '     '$status $body_bytes_sent "$http_referer" '     '"$http_user_agent" "$http_x_forwarded_for"'; #日志格式   server_names_hash_bucket_size 128;   client_max_body_size 320m;   client_body_buffer_size 128k;   client_header_buffer_size 32k;   large_client_header_buffers 4 64k;   open_file_cache max=102400 inactive=20s; #缓存最大数和缓存时间   open_file_cache_valid 30s; #检测正确信息的间隔时间   open_file_cache_min_uses 1; #不活动期间最小文件数
  #open_file_cache_errors on; # 搜索文件是否缓存错误信息   sendfile on; #传输加速,内核中完成,无需用户空间   tcp_nopush on; #头文件打包发送,而不是一个一个发送   tcp_nodelay on; #不缓存数据直接发送   server_tokens off; #关闭错误页面中nginx版本显示   keepalive_timeout
10; #client超时时间   client_header_timeout 10; #请求头超时时间   client_body_timeout 10; #请求体超时时间   reset_timedout_connection on; #关闭不响应客户端连接
  send_timeout 10; #两次client读取之间没有没有任何数据返回给client,关闭连接
  limit_conn_zone $binary_remote_addr zone
=addr:5m; #保存key的共享内存参数   limit_conn addr 200; #一个ip最多打开连接数   if_modified_since before;   # limit_rate_after 100k;   # limit_rate 10k;

  upstream front {
    server 127.0.0.1:8000 weight=50 max_fails=3 fail_timeout=30s;
    server 127.0.0.1:9000 weight=50 max_fails=3 fail_timeout=30s;
  }

  upstream backend {
    ip_hash;
    server 192.168.1.7:7080 max_fails=3 fail_timeout=60s;
    server 192.168.1.8:8080 max_fails=3 fail_timeout=60s;
  }

  server {
    listen 80;
    server_name localhost;
    root /path;
    index /path/index.html;

    location / {
      proxy_pass http://front;
      proxy_http_version 1.1;
    }
    location ~ /\. {
      access_log off;
      log_not_found off;
      deny all;
    }
    location /ngx_status {
      stub_status on;
      auth_basic "NginxStatus";
    }
  }

include conf.d/*.conf;
}

 gzip.conf

gzip on;
gzip_http_version 1.0;
gzip_disable      "MSIE [1-6]\."; #不压缩浏览器版本
gzip_disable      "Mozilla/4";
gzip_comp_level  4; #压缩等级
#gzip_static  on; gzip_proxied any; #同意或者禁止压缩基于请求和响应的响应流(any全部压缩) gzip_vary on; gzip_buffers
4 32k; gzip_min_length 1100; #最小文件压缩阀值 gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/atom_xml application/javascript application/x-javascript application/x-shockwave-flash video/x-flv image/jpeg image/gif;

proxy.conf

proxy_redirect          off;
proxy_hide_header      Vary;
proxy_set_header        Accept-Encoding '';
proxy_set_header        Host           $host;
proxy_set_header        X-Real-IP      $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header        X-Forwarded-Proto $scheme;
proxy_connect_timeout  60;
proxy_send_timeout      600;
proxy_read_timeout      600;
proxy_set_header   Connection "keep_Alive";
proxy_buffer_size      128k;
proxy_buffers          8 128k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 128k;
proxy_max_temp_file_size 100m;

 

posted on 2017-10-26 16:53  Copernicus  阅读(134)  评论(0)    收藏  举报

导航