运行 nginx + gunicorn + django-plotly-dash 时获取请求问题

运行 nginx + gunicorn + django-plotly-dash 时获取请求问题

网站正在运行,Gigicorn 有多个工作器。出于某种原因,url_calling:http://web?id=value id=value 不能连贯地传播(有时可以,但大多数时候不行),我遗漏了什么?

Gigicorn 会议:

#bind = ['127.0.0.1:8000', '127.0.0.1:8001', '127.0.0.1:8002','127.0.0.1:8003','127.0.0.1:8004','127.0.0.1:8005','127.0.0.1:8006','127.0.0.1:8007','127.0.0.1:8008',]
bind = 'unix:/tmp/unicorn.sock'
workers = 8
user = 'someuser'
timeout = 120

log_level = 'debug'
accesslog = '/var/log/gunicorn/access.log'
errorlog = '/var/log/gunicorn/error.log'

capture_output = True
enable_stdio_inheritance = True

nginx 配置:

server {
    listen 80;
    #listen 80 default_server;
    #listen [::]:80 default_server;
    #server_name django.somedomain.com;

    access_log /var/log/nginx_access.log;
    error_log /var/log/nginx_error.log;


    location = /icon.png  {
            access_log off;
            log_not_found off;
    }
    location /static/ {
        autoindex off;
        autoindex_exact_size off;
        root /myroot/dj/plotly-dash-django-udemy/;
    }

    #location / {
    #    include proxy_params;
    #    proxy_pass http://localhost:8000;

    #}

   location / {
       include proxy_params;
       proxy_pass http://unix:/tmp/unicorn.sock;
   }


}

nginx 文件夹结构:

/etc/nginx$ ll *
-rw-r--r-- 1 root root 3071 Jul 27 01:32 win-utf
-rw-r--r-- 1 root root  664 Jul 27 01:32 uwsgi_params
-rw-r--r-- 1 root root  636 Jul 27 01:32 scgi_params
-rw-r--r-- 1 root root  180 Jul 27 01:32 proxy_params
-rw-r--r-- 1 root root 2223 Jul 27 01:32 koi-win
-rw-r--r-- 1 root root 2837 Jul 27 01:32 koi-utf
-rw-r--r-- 1 root root 1055 Jul 27 01:32 fastcgi_params
-rw-r--r-- 1 root root 1125 Jul 27 01:32 fastcgi.conf
-rw-r--r-- 1 root root 2412 Jul 27 01:32 default.sites-available
-rw-r--r-- 1 root root 3957 Aug  2 07:22 mime.types
lrwxrwxrwx 1 root root   34 Dec 19 22:50 default.config -> /etc/nginx/sites-available/default
-rw-r--r-- 1 root root 1443 Dec 21 08:44 nginx.conf

modules-available:
total 0

snippets:
total 8
-rw-r--r-- 1 root root 217 Jul 27 01:32 snakeoil.conf
-rw-r--r-- 1 root root 423 Jul 27 01:32 fastcgi-php.conf

modules-enabled:
total 8
lrwxrwxrwx 1 root root 60 Dec 19 22:50 50-mod-http-xslt-filter.conf -> /usr/share/nginx/modules-available/mod-http-xslt-filter.conf
lrwxrwxrwx 1 root root 55 Dec 19 22:50 50-mod-http-geoip2.conf -> /usr/share/nginx/modules-available/mod-http-geoip2.conf
lrwxrwxrwx 1 root root 48 Dec 19 22:50 50-mod-mail.conf -> /usr/share/nginx/modules-available/mod-mail.conf
lrwxrwxrwx 1 root root 61 Dec 19 22:50 50-mod-http-image-filter.conf -> /usr/share/nginx/modules-available/mod-http-image-filter.conf
lrwxrwxrwx 1 root root 50 Dec 19 22:50 50-mod-stream.conf -> /usr/share/nginx/modules-available/mod-stream.conf
lrwxrwxrwx 1 root root 57 Dec 19 22:50 70-mod-stream-geoip2.conf -> /usr/share/nginx/modules-available/mod-stream-geoip2.conf

sites-enabled:
total 0
lrwxrwxrwx 1 root root 43 Dec 20 08:38 djando.veloquant.com.conf -> /etc/nginx/conf.d/djando.veloquant.com.conf

sites-available:
total 0
lrwxrwxrwx 1 root root 43 Dec 21 11:19 djando.veloquant.com.conf -> /etc/nginx/conf.d/djando.veloquant.com.conf

conf.d:
total 4
-rw-r--r-- 1 root root 668 Dec 21 10:35 djando.veloquant.com.conf     

答案1

解决方案是将 query_string 配置添加到 proxy_params :

猫/等/ nginx / proxy_params

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
#new lines that solved the issue:
proxy_set_header X-Path-Info $uri;
proxy_set_header X-Query-String $query_string;

相关内容