【问题标题】:Django server - 502 error bad gatewayDjango 服务器 - 502 错误网关错误
【发布时间】:2017-06-30 00:17:12
【问题描述】:

我有一个带有 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;
}

【问题讨论】:

    标签: django nginx config


    【解决方案1】:

    我对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;
    
    }
    

    你可以试一试。

    【讨论】:

    • 还要检查用户权限。如果您已经设置了 virtualenv,并且以与 nginx 不同的用户身份运行,那么它可能无法访问文件。
    猜你喜欢
    • 2019-06-07
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 2019-12-01
    • 2022-07-01
    • 2020-09-29
    • 2012-07-16
    • 2021-06-30
    相关资源
    最近更新 更多