标签: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
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
原文地址:http://blog.51cto.com/nanfeibobo/2103924