Python Nginx网关超时,服务器上没有太多负载
我正在使用NGINX和UWSGI为基于python/Django的API后端提供动力,并将负载平衡器连接到AWS auto-scale组。我的服务器在日常工作中运行良好,但有时会在一两个月内从服务器获取504或502,持续一天或更长时间。我的服务器上的负载比例程少,内存使用情况良好,但仍然得到502或504 使用ubuntu 14.0.4 以下是我的nginx配置的外观Python Nginx网关超时,服务器上没有太多负载,python,django,amazon-web-services,nginx,uwsgi,Python,Django,Amazon Web Services,Nginx,Uwsgi,我正在使用NGINX和UWSGI为基于python/Django的API后端提供动力,并将负载平衡器连接到AWS auto-scale组。我的服务器在日常工作中运行良好,但有时会在一两个月内从服务器获取504或502,持续一天或更长时间。我的服务器上的负载比例程少,内存使用情况良好,但仍然得到502或504 使用ubuntu 14.0.4 以下是我的nginx配置的外观 user www-data; worker_processes 2; pid /run/nginx.pid; events {
user www-data;
worker_processes 2;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
worker_rlimit_nofile 40000;
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 50s;
keepalive_requests 1024;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
client_body_timeout 12;
client_header_timeout 12;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:10m;
limit_conn addr 20;
open_file_cache max=5000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
log_format json '{"method": "$request_method", "uri":
"$request_uri", "status": $status, "request_time": $request_time,
"upstream_response_time": $upstream_response_time, "body_bytes_sent":
$body_bytes_sent, "http_user_agent": "$http_user_agent", "remote":
"$remote_addr", "upstream": "$upstream_addr", "proxy": "$proxy_host"}';
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 9;
#gzip_buffers 16 8k;
#gzip_http_version 1.1;
#gzip_types text/plain text/css application/json;
gzip_types text/plain text/css application/json application/x-
javascript text/xml application/xml application/xml+rss text/javascript;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
首先,确定哪台服务器返回超时错误。
负载平衡器或Nginx Worker希望这能帮助一些具有类似设置的人 设置: 在我的例子中,在GCP上,一个NGINX实例被放置在一个子网内,对于这个子网, NGINX连接了一个NAT网关以访问公共互联网 由于此NGINX使用了
代理\u pass
传递给与后端API关联的域,因此它需要访问internet
遇到错误:
在同时发出多个请求之后,我在NGINX错误日志上得到了504超时。
总之:110连接到上游时超时
解决方案:
增加NAT网关上每个VM实例的最小端口数。
不需要更改NGINX配置
每个VM实例的最小端口数最初设置为64,当请求数增加时,这是不够的
您使用的是ELB还是您自己的负载平衡器?502/504错误是由负载平衡器还是由nginx服务器返回的?您有权访问nginx和uwsgi日志吗?我们正在使用ELB,520/504由nginx返回,有时也在ELB上返回。而不是易北河。我们确实可以访问Nginx和UWSGI日志sso如果您查看产生502错误的请求,您会在Nginx和UWSGI日志中看到这些请求的什么?一定在某个地方记录了错误。