Nginx作为反向代理Django Gunicorn返回400错误请求

时间:2019-02-01 18:33:02

标签: django nginx gunicorn nginx-reverse-proxy

我正在尝试使用nginx作为反向代理来接收传入的呼叫,然后根据server_name将这些呼叫重定向到运行nginx Django和Gunicorn的其他计算机(主机)。到目前为止,我已经为主机上的conf文件尝试了不同的配置,但是它们都不起作用。我的conf文件有什么问题吗?

这是192.168.0.13中的nginx.conf,它将用作反向代理:

server {
  listen 80;
  server_name www.coding.test;

  location / {
        proxy_pass http://192.168.0.8:80;
        proxy_redirect     off;
        # app1 reverse proxy follow
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}

这是192.168.0.8中旨在运行django应用程序的nginx.conf:

upstream django {
    server unix:///home/pi/coding-in-dfw/mysocket.sock fail_timeout=0;
}

server {
    listen 80 default_server;
    server_name www.coding.test

    client_max_body_size 4G;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location /static/ {
        alias   /home/pi/coding-in-dfw/static/;
    }

    location /media/ {
        alias   /home/pi/coding-in-dfw/media/;
    }

    # Finally, send all non-media requests to the Django server.
    location / {
         uwsgi_pass  django;
         include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
     }
     location /.well-known {
         alias /home/pi/coding-in-dfw/.well-known;
     }
}

最后,这就是我运行古尼康的方式:

gunicorn --workers 5 --bind unix:///home/pi/coding-in-dfw/mysocket.sock codingindfw.wsgi:application && sudo service nginx restart

感谢您的帮助。

0 个答案:

没有答案
相关问题