apache - NGINX - HTTP 500 上游过早关闭连接,同时从上游读取响应标头
问题描述
我们在 docker 容器中有一个 Apache 服务器,在另一个容器中有 NGINX 作为代理服务器。有时我的网站会停止响应 HTTP 500 或 HTTP 502 错误。当我检查 NGINX 的错误日志时,我收到以下错误:
*upstream prematurely closed connection while reading response header from upstream*
经过一些研究,我发现很多人通过增加 time_out 来解决它,但这里不应该是这种情况,因为我在从我的网站发送一些申请后立即收到此错误。我也不认为这应该是资源问题,因为在发送请求后我检查了消耗,它并没有显着增加。我使用以下命令来检查它:
docker stats
htop
我们还验证了 NGINX 的问题,将请求直接发送到我的网站时,我没有遇到任何错误。
我的 NGINX 配置是:
server_tokens off;
#client_max_body_size 1G;
#client_body_buffer_size 80M;
proxy_cache_path /tmp/cache keys_zone=one:10m;
#proxy_request_buffering off;
#proxy_buffering off;
upstream mySite
{
server 10.20.40.1:443;
#server 10.20.40.2:443;
#server 10.20.40.3:443;
}
log_format name '[$time_local] src_ip="$remote_addr" X-Forwarded-For="$http_x_forwarded_for"
http_hostname="$host" connection="$sent_http_connection" remote_user="$remote_user"
request="$request" http_status="$status" bytes_sent="$body_bytes_sent"
content_length="$http_content_length" referer="$http_referer" user_agent="$http_user_agent"
session_id="$cookie_PHPSESSID" http_method="$request_method" connection_serial="$connection"
request_time="$request_time" proxy_host="$proxy_host" upstream_addr="$upstream_addr"
upstream_status="$upstream_status" upstream_cache_status="$upstream_cache_status"
upstream_response_time="$upstream_response_time"';
server
{
listen 80;
listen 443 ssl reuseport;
listen [::]:80;
listen [::]:443 ssl;
proxy_cache one;
#access_log /var/log/nginx/lbmySite-access.log name;
#error_log /var/log/nginx/lbmySite-error.log;
access_log syslog:server=10.20.10.1:6515 name;
ssl_certificate /opt/mySite_certs/mySite_cert.crt;
ssl_certificate_key /opt/mySite_certs/mySite_cert.key;
proxy_buffering on;
#access_log off;
location /
{
proxy_set_header Host $host;
proxy_pass https://mySite;
proxy_redirect off;
#proxy_connect_timeout 120s;
#proxy_set_header Host $host;
proxy_set_header X-Connection-Serial $connection;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
解决方案
推荐阅读
- sql - 每个属性的表“f”缺少 FROM 子句条目
- graphql - Apollo 客户端:发送与身份验证/授权相关的不同标头
- java - 科尔多瓦项目中的以下错误是什么意思?
- c# - 如何将 JWT 从 Web-API 发送到 MVC?
- javascript - 在内容脚本上调试“JSON 输入错误的意外结束”
- sql - DB2 select ... insert 无法将闰日转换为日期
- powershell - PowerShell:如何从多列输出中的单列设置变量?
- java - 为什么在此文件上运行 readAllBytes 时出现 NoSuchFileException
- jsf - 为什么登录表单中保存的密码会放到内部页面的其他JSF组件中?
- javascript - 如何将锚标记的 id 附加到 jquery 中的新 href 并替换页面中的 href 属性?