【发布时间】:2018-04-09 08:21:06
【问题描述】:
我目前正在尝试使用 Nginx 在 REHL 7.4 服务器上部署 Django 应用程序。我遵循了这些教程:
virtualenv 和 nginx 服务器似乎没问题。但是我正在努力解决两个错误:
-
由于 worker_connections 参数值(以下是日志),我得到了 500 错误:
13494#0: *1021 1024 worker_connections 在连接上游时不够用,客户端:192.168.1.33,服务器:192.168.1.33,请求:“GET /Syc/login HTTP/1.0”,上游:“http://192.168.1.33:80/Syc/login ", 主机: "192.168.1.33"
要么我将 worker_connections 值增加到 > 4096,然后我得到一个 400 错误,就像在这个线程 400 Bad Request - request header or cookie too large
以下是我的 nginx.conf 和 app.conf,如果有配置错误请告诉我,提前感谢任何帮助。
nginx.conf:
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
# set open fd limit to 30000
worker_rlimit_nofile 30000;
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
large_client_header_buffers 4 32k;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
app.conf
upstream app_server {
server unix:/opt/sycoma/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name 192.168.1.33; # <- insert here the ip address/domain name
large_client_header_buffers 4 16k;
keepalive_timeout 5;
client_max_body_size 4G;
access_log /opt/sycoma/logs/nginx-access.log;
error_log /opt/sycoma/logs/nginx-error.log;
location /static/ {
alias /opt/sycoma/venv/Sycoma/Syc/static/;
}
location /media/ {
alias /opt/sycoma/venv/Sycoma/media/;
}
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://192.168.1.33;
}
}
【问题讨论】: