在nginx服务器rhel-400上部署django应用程序,请求头或cookie太大



我目前正在尝试使用Nginx在REHL 7.4服务器上部署Django应用程序。我遵循了以下教程:

https://simpleisbetterthancomplex.com/tutorial/2017/05/23/how-to-deploy-a-django-application-on-rhel.html

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

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错误请求-请求标头或cookie太大

下面是我的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;
}
}

尝试删除/注释行:

proxy_set_header Host $http_host;

或增加CCD_ 1。

最新更新