【问题标题】:(Bad Gateway) ERROR 502 Nginx, Gunicorn, Django DRF, Vue.js(错误网关)错误 502 Nginx、Gunicorn、Django DRF、Vue.js
【发布时间】:2021-11-19 22:58:54
【问题描述】:

我已经在 VPS 上部署了使用 Django 和 Vue.js 制作的电子商务。一切正常,但是当我尝试使用 POST 方法时,控制台中出现错误 502 并且没有任何反应。 API 能够显示来自 Django Admin 的产品,但我无法从前端发布任何内容。它总是给我这个错误 502 问题。我已经尝试解决这个问题几天了,但仍然不知道出了什么问题。希望你能帮忙。谢谢!

upstream perulab_app_server {
    server unix:/webapps/perulab/venv/run/gunicorn.sock fail_timeout=0;
}

server {
    listen 8000;
    listen [::]:8000;
    server_name 172.16.7.52;

    client_max_body_size 40M;

    location / {
        root /webapps/perulab/web-frontend/dist;
        try_files $uri /index.html;
        index index.html index.htm;
    }

    location /static/ {
        root /webapps/perulab/web-backend;
    }

    location /media/ {
        root /webapps/perulab/web-backend;
    }
        
    location /api/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://perulab_app_server/api/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }

    location /admin/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://perulab_app_server/admin/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
}

当我尝试运行 gunicorn --bind 172.16.7.52:8000 core.wsgi 时,会出现以下内容:

[2021-09-27 14:55:59 -0500] [230558] [INFO] Starting gunicorn 20.1.0
[2021-09-27 14:55:59 -0500] [230558] [ERROR] Connection in use: ('172.16.7.52', 8000)
[2021-09-27 14:55:59 -0500] [230558] [ERROR] Retrying in 1 second.
[2021-09-27 14:56:00 -0500] [230558] [ERROR] Connection in use: ('172.16.7.52', 8000)
[2021-09-27 14:56:00 -0500] [230558] [ERROR] Retrying in 1 second.
[2021-09-27 14:56:01 -0500] [230558] [ERROR] Connection in use: ('172.16.7.52', 8000)
[2021-09-27 14:56:01 -0500] [230558] [ERROR] Retrying in 1 second.
[2021-09-27 14:56:02 -0500] [230558] [ERROR] Connection in use: ('172.16.7.52', 8000)
[2021-09-27 14:56:02 -0500] [230558] [ERROR] Retrying in 1 second.
[2021-09-27 14:56:03 -0500] [230558] [ERROR] Connection in use: ('172.16.7.52', 8000)
[2021-09-27 14:56:03 -0500] [230558] [ERROR] Retrying in 1 second.
[2021-09-27 14:56:04 -0500] [230558] [ERROR] Can't connect to ('172.16.7.52', 8000)

似乎有东西占用了空间,所以为了让这个命令起作用,我首先需要杀死所有进程,然后运行这个命令。在那之后,整个网络应用程序就宕机了。

我试图在同一个端口上运行所有内容。也许这就是问题所在,我不知道如何为此正确设置 Nginx。

更新:在测试完所有内容后,看起来 API 仅适用于不发送电子邮件的视图类。任何具有send_mail() 的视图都会生成此错误 502 问题。我还是不知道怎么解决。

【问题讨论】:

    标签: django vue.js nginx django-rest-framework gunicorn


    【解决方案1】:

    我能够解决这个问题。在这种情况下,上面的设置很好。除发送电子邮件的 API 外,所有 API 均正常工作。所以,问题出在邮件服务器上,我无法从 DNS 发送电子邮件。一旦解决了这个问题,一切就开始正常了。

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 2018-12-05
      • 2017-07-07
      • 2014-12-07
      • 2015-04-22
      • 2016-06-23
      • 2020-09-29
      • 2012-07-16
      • 2017-10-01
      相关资源
      最近更新 更多