nginx相關配置
阿新 • • 發佈:2018-04-16
nginx
參考:Nginx 作為反向代理優化要點proxy_buffering
利用nginx做反向代理時,配置文件可以參考下面的配置:
user nginx; worker_processes 2; error_log logs/error.log warn; pid logs/nginx.pid; events { worker_connections 10240; multi_accept on; use epoll; } http { include mime.types; default_type application/octet-stream; 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 logs/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; underscores_in_headers on;#off 表示如果header name中包含下劃線,則忽略掉,部署後就獲取不到 on則相反 keepalive_timeout 240; server_tokens off; #隱藏版本號 send_timeout 10m; client_header_buffer_size 256k; client_max_body_size 1000m; client_body_timeout 10m; client_header_timeout 10m; large_client_header_buffers 8 64k; client_body_buffer_size 20m; fastcgi_buffers 6 256k; fastcgi_buffer_size 1024k; fastcgi_busy_buffers_size 1024k; proxy_request_buffering off; proxy_buffering off; #開啟從後端被代理服務器的響應內容緩沖 proxy_buffer_size 128k; #設置緩沖區的大小和數量 proxy_buffers 100 128k; proxy_busy_buffers_size 128k; upstream NAME { server host:port; } upstream NAME_SSL { server host:443; } server { listen 80; server_name a.example.com; charset utf8; ignore_invalid_headers off; error_page 404 403 =https://a.example.com/404.html; location / { include conf.d/deny_appid.conf; #location自定義配置 proxy_pass http://NAME/; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Cookie $http_cookie; chunked_transfer_encoding off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; } } server { listen 443 ssl; server_name a.example.com; ignore_invalid_headers off; charset utf8; ssl_certificate example.com.crt; ssl_certificate_key example.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; error_page 404 403 =https://a.example.com/404.html; location / { include conf.d/deny_appid.conf; proxy_pass https://NAME_SSL/; proxy_ssl_session_reuse off; proxy_redirect off; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Cookie $http_cookie; chunked_transfer_encoding off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; } } }
nginx+tomcat 報錯:『an upstream response is buffered to a temporary file 』
參考鏈接:http://blog.51cto.com/11413817/1950467
nginx的an upstream response is buffered to a temporary file報錯
client_header_buffer_size 256k; 把原來的32k改為256k
nginx fastcgi_buffers to an upstream response is buffered to a temporary file
fastcgi_buffers 16 16k; 指定本地需要用多少和多大的緩沖區來緩沖FastCGI的應答,如上所示,如果一個php腳本所產生的頁面大小為256k,則會為其分配16個16k的緩沖區來緩存,如果大於256k,增大於256k的部分會緩存到fastcgi_temp指定的路徑中,當然這對服務器負載來說是不明智的方案,因為內存中處理數據速度要快於硬盤,通常這個值的設置應該選擇一個你的站點中的php腳本所產生的頁面大小的中間值,比如你的站點大部分腳本所產生的頁面大小為256k就可以把這個值設置為16 16k,或者4 64k 或者64 4k,但很顯然,後兩種並不是好的設置方法,因為如果產生的頁面只有32k,如果用4 64k它會分配1個64k的緩沖區去緩存,而如果使用64 4k它會分配8個4k的緩沖區去緩存,而如果使用16 16k則它會分配2個16k去緩存頁面,這樣看起來似乎更加合理。 //+++++++++++++++++++++++++++++++++++++++++ client_max_body_size 100m; #允許客戶端請求的最大單文件字節數 client_body_buffer_size 2048k; #緩沖區代理緩沖用戶端請求的最大字節數, fastcgi_buffer_size 1024k; fastcgi_buffers 6 256k; fastcgi_busy_buffers_size 1024k; fastcgi_buffer等於:fastcgi_buffer_size + the_number * is_size fastcgi_buffers 256 4k; #設置buffer大小為:4k + 256 * 4k = 1028k 上面配置可以解決 an upstream response is buffered to a temporary file 或nginx+php-fpm慢問題
php502問題解決:recv() failed (104: Connection reset by peer) while reading response header from upstream
參考:https://blog.csdn.net/donglynn/article/details/76759548
nginx error: upstream prematurely closed connection while reading response header from upstream
參考:https://www.cnblogs.com/xinpureZhu/p/6142183.html
nginx access log 關閉
access_log off;
nginx error_log 日誌調整級別:
error_log logs/error.log info|notice|warn|error;
nginx相關配置