nginx配置优化-生产环境应用版
user www www; worker_processes auto; worker_cpu_affinity auto; error_log /usr/local/nginx/logs/error.log warn; pid nginx.pid; worker_rlimit_nofile 65535; events { use epoll; multi_accept on; worker_connections 65530; } http { include mime.types; default_type application/octet-stream; charset utf-8; server_tokens off; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 40s; client_header_timeout 10; client_body_timeout 10; client_header_buffer_size 4k; server_names_hash_bucket_size 128; large_client_header_buffers 4 32k; client_max_body_size 100m; send_timeout 10; reset_timedout_connection on; open_file_cache max=102400 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; #出现110错误需要更改相应大小值 fastcgi_buffers 256 128k; fastcgi_busy_buffers_size 256k; #fastcgi_buffers的两倍 fastcgi_temp_file_write_size 256k; #fastcgi_buffers的两倍 proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 128k; #出现110错误需要更改相应大小值 proxy_buffers 256 128k; proxy_busy_buffers_size 256k; #proxy_buffers的两倍 proxy_temp_file_write_size 256k; #proxy_buffers的两倍 gzip on; gzip_min_length 256; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 5; gzip_disable "MSIE [1-6]\."; gzip_proxied any; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; log_format access '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"url":"$uri",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"agent":"$http_user_agent",' '"status":"$status"}'; access_log /usr/local/nginx/logs/access.log access; server { listen 80; server_name localhost; index index.html index.php; root /data/www/default; access_log /usr/local/nginx/logs/access.log; error_log /usr/local/nginx/logs/error.log; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } location ~ \.php { expires -1; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }