Django服务器 - 502错误坏网关

时间:2017-06-30 00:17:12

标签: django nginx config

我有一个带有virtualenv的centOS,我可以在我的localhost中使用该项目,但是当项目上传到服务器时会出错:

502 - 糟糕的网关

我认为问题可能出在我的nginx文件中。

server {
listen 80;
server_name www.site.com.br site.com.br;
root /var/www/html/agrodez/src/;

if ($http_host != "www.site.com.br") {
    rewrite ^ http://site.com.br$request_uri permanent;

}
location /static/ {
    alias /var/www/html/site/src/sistema/static/;

}
location /{
    proxy_pass http://localhost:8000;
    include /etc/nginx/proxy_params;
}

1 个答案:

答案 0 :(得分:0)

我对django了解不多,但最近我不得不帮助一个配置服务器的团队,并且我使用了以下nginx虚拟主机配置:

upstream django.local {
    server 127.0.0.1:8000;
}
server {
    listen       80;
    server_name  site.com;

    location / {
        root   html;
        index  index.html index.htm;
        proxy_pass http://django.local/;
    }

    location /static {
        autoindex on;
        # this line would be STATIC_ROOT dir
        alias /var/www/html/agrodez/src/staticfiles;
    }

    location /media {
        autoindex on;
        # this line would be MEDIA_ROOT dir;
        alias /var/www/html/agrodez/src/media;
    }

    # If you want nginx logs, then can add these
    error_log /var/log/nginx/site.com_error.log;
    access_log /var/log/nginx/site.com_access.log;

}

你可以尝试一下。