本文章主要介绍了nginx配置文件,具有不错的的参考价值,希望对您有所帮助,如解说有误或未考虑完全的地方,请您留言指出,谢谢!
worker_processes 4; worker_cpu_affinity 0001 0010 0100 1000; user nginx; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; tcp_nodelay on; server_tokens off; client_header_timeout 15; send_timeout 15; client_max_body_size 50m; #上传文件大小设置 keepalive_timeout 65; gzip on; #开启压缩功能 gzip_min_length 10k; #允许压缩的最小页面字节数,从header头的Content-Length中获取,不管页面多大都进行压缩,建议设置成大于1K,如果小于1K可能会越压缩越大 gzip_http_version 1.1; #压缩版本,默认为1.1,目前大部分浏览器都支持压缩 gzip_buffers 4 32k; #压缩缓冲大小,允许申请4个单位为32K的内存作为流缓存 gzip_comp_level 9; #压缩比例,1最小,9最大,传输速度最快,但是比较消耗资源 gzip_types text/css text/xml application/javascript; #指定压缩的内容类型 gzip_vary on; #vary header支持,让前端的缓存服务器继续缓存传输该压缩页面,而不提前解压 add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options: nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Strict-Transport-Security: max-age=31536000; add_header Content-Security-Policy "upgrade-insecure-requests;connect-src *"; # '$status $body_bytes_sent "$http_referer" '; 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; upstream server_pool1 { #ip_hash; sticky expires=1h domain=bj32un.com path=/*; server 10.0.0.22:8080 weight=1 max_fails=3 fail_timeout=10s ; server 10.0.0.23:8080 weight=1 max_fails=3 fail_timeout=10s ; }
upstream server_pool1 {
#ip_hash;
sticky expires=1h domain=bj32un.com path=/*;
server 10.0.0.2:8080 weight=1 max_fails=3 fail_timeout=10s ;
server 10.0.0.3:8080 weight=1 max_fails=3 fail_timeout=10s ;
}
server { server_name baidu.bj32un.com; listen 10.0.0.253:80; location / { root /usr/local/nginx/html; #index maintain.html; index index.html; } location /dctj { proxy_pass http://server_pool1; #alias /usr/local/nginx/html; #index maintain.html; 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_intercept_errors on; } location /web01 { proxy_pass http://server_pool1; #alias /usr/local/nginx/html; #index maintain.html; 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_intercept_errors on; } location /web02{ proxy_pass http://server_pool1; #alias /usr/local/nginx/html; #index maintain.html; 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_intercept_errors on; } error_page 403 502 504 = $scheme://$host/error.html; error_page 404 = $scheme://$host/404.html; error_page 500 = $scheme://$host/500.html; error_page 503 = $scheme://$host/503.html; } server { server_name baidugl.bjz32yun.com; listen 10.0.0.223:80; server_tokens off; location / { root /usr/local/nginx/html; #index maintain.html; index index.html; } location /webgl { proxy_pass http://server_pool1; #alias /usr/local/nginx/html; #index maintain.html; 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_intercept_errors on; } error_page 403 502 504 = $scheme://$host/error.html; error_page 404 = $scheme://$host/404.html; error_page 500 = $scheme://$host/500.html; error_page 503 = $scheme://$host/503.html; } }
原创文章,作者:1402239773,如若转载,请注明出处:https://blog.ytso.com/228364.html