Nginx 配置文件总结
顶级配置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 user nginx;pid /var/run/nginx.pid;error_log /var/log/nginx/error .log warn ;worker_processes 8 ;worker_rlimit_nofile 65535 ;
修改系统文件打开数量限制:
1 sudo sh -c ulimit -HSn 65535 // 临时修改
重启后永久生效,则需要设置修改:
1 sudo vim /etc/ security/limits.conf
在文件尾部添加:
1 2 * soft nofile 200000* hard nofile 200000
Events 模块 1 2 3 4 5 6 7 8 9 10 events { worker_connections 2048 ; multi_accept on ; use epoll ; }
HTTP 模块 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 http { server_tokens off ; sendfile on ; autoindex off ; tcp_nopush on ; tcp_nodelay on ; log_format main '$remote_addr - $remote_user [$time_local ] "$request " ' '$status $body_bytes_sent "$http_referer " ' '"$http_user_agent " "$http_x_forwarded_for "' ; access_log /var/log/nginx/access.log main; keepalive_timeout 120 ; client_header_timeout 60 ; client_body_timeout 10 ; send_timeout 60 ; reset_timedout_connection off ; limit_conn_zone $binary_remote_addr zone=addr:5m ; limit_conn addr 100 ; limit_rate 100k ; include /etc/nginx/mime.types; default_type text/html; charset UTF-8 ; gzip_static off ; gzip on ; gzip_disable "msie6" ; gzip_proxied any; gzip_min_length 1024 ; gzip_comp_level 5 ; gzip_buffers 4 16k ; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; open_file_cache max=65535 inactive=30s ; open_file_cache_valid 30s ; open_file_cache_min_uses 2 ; open_file_cache_errors on ; include /etc/nginx/conf.d/*.conf ; include /etc/nginx/sites-enabled/*; }
SERVER 模块 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 server { listen 80 default_server; server_name www.test.com test.com; root /user/share/nginx/html/test; error_page 404 /404 .html; ssl on ; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; location / { index index.html index.php; } location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ { expires 10d ; } location ~ .*.(js|css)?$ { expires 1h ; } location ~ [^/]\.php(/|$) { fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$ ; fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name ; fastcgi_param PATH_INFO $fastcgi_path_info ; fastcgi_param PATH_TRANSLATED $document_root $fastcgi_path_info ; fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; } }
参考资料: