【发布时间】:2018-03-02 11:08:32
【问题描述】:
我正在使用 NGINX 和 UWSGI 为基于 python/Django 的 API 后端提供动力,负载均衡器连接到 AWS 自动缩放组,我的服务器在日常工作中运行良好,但有时在一两个月内开始从服务器获取 504 或 502持续一天或更长时间。我的服务器上的负载低于常规,内存使用情况很好,但仍然得到 502 或 504
使用 ubuntu 14.0.4
这是我的 nginx 配置的样子
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/*;
}
【问题讨论】:
-
您使用的是 ELB 还是您自己的负载均衡器? 502/504 错误是由负载均衡器还是由您的 nginx 服务器返回的?您是否有权访问 nginx 和 uwsgi 日志?
-
我们正在使用 ELB,Nginx 返回 520/504,有时也在 ELB 上。而不是ELB。我们确实可以访问 Nginx 和 UWSGI 日志
-
因此,如果您查看产生 502 错误的请求,您会在 nginx 和 uwsgi 日志中看到这些请求的什么内容?一定有错误记录在某处。
标签: python django amazon-web-services nginx uwsgi