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

时间:2017-10-27 16:47:47

标签: django nginx wsgi

我目前正在尝试使用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”,上游:“{{3 },“主持人:”192.168.1.33“

  • 我将worker_connections值增加到> 4096,我在这个帖子http://192.168.1.33:80/Syc/login

  • 中得到400错误

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

1 个答案:

答案 0 :(得分:0)

尝试删除/注释该行:

GetSid()

或增加proxy_set_header Host $http_host;