参考:Nginx 做为反向代理优化要点proxy_bufferingphp
利用nginx作反向代理时,配置文件能够参考下面的配置:html
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 』 node
参考连接:http://www.javashuo.com/article/p-aaklndcs-er.html nginx
client_header_buffer_size 256k; 把原来的32k改成256k
nginx fastcgi_buffers to an upstream response is buffered to a temporary filesegmentfault
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后端
参考:http://www.javashuo.com/article/p-wmmcfbbn-ec.html 缓存
nginx error: upstream prematurely closed connection while reading response header from upstream tomcat
参考:http://www.javashuo.com/article/p-frryvann-ea.html bash
nginx access log 关闭服务器
access_log off;
nginx error_log 日志调整级别:
error_log logs/error.log info|notice|warn|error;