【问题标题】:Getting 502 error when I try to send email, server setup by django, postgres, nginx, gunicorn当我尝试发送电子邮件时出现 502 错误,由 django、postgres、nginx、gunicorn 设置服务器
【发布时间】:2018-08-05 14:16:35
【问题描述】:

我正在关注来自数字海洋How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 16.04的本教程

一切正常,除了当我尝试使用 gmail 发送电子邮件时,它会抛出 502 bad gateway。 nginx日志文件显示

94 上游从上游读取响应头时过早关闭连接

gunicorn 配置

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=webuser
Group=www-data
WorkingDirectory=/home/webuser/chhuti_ata
ExecStart=/home/webuser/venv/chhuti/bin/gunicorn --access-logfile - --
workers 3 --bind unix:/home/webuser/chhuti_ata/chhuti.sock 
chhuti.wsgi:application
[Install]
WantedBy=multi-user.target

nginx 配置

server {
    listen 80;
    server_name ***.***.***.***;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/webuser/chhuti_ata;
    }

    location /media/ {
        root /home/webuser/chhuti_ata;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/webuser/chhuti_ata/chhuti.sock;
    }
}

任何帮助将不胜感激。

【问题讨论】:

  • 请添加配置文件
  • 您现在可以检查一下吗

标签: django nginx gunicorn


【解决方案1】:

我认为来自 Nginx 的错误表明连接在完成发送电子邮件之前已提前关闭。如果您通过 gmail 发送电子邮件,出于安全目的,gmail 有时会从身份不明的登录或“不安全的应用程序”(即从托管您的 django 应用程序的服务器的登录)中block the log-in(以及发送电子邮件)。

您可能需要检查您的 gmail 安全设置以手动确保 gmail 允许运行您的 django 应用程序的网络服务器(特别是识别服务器 IP)发送电子邮件。

如果这不起作用,您可能需要将 DJango 配置为异步发送电子邮件,请参阅 here

【讨论】:

  • 谢谢,我已将 google 设置更改为不太安全的设置。并在 nginx 中也将超时更改为 7500,但没有运气。
  • 您的服务器登录信息是否显示在 gmail 安全页面上。 gmail 有一个登录历史页面,显示所有尝试登录;你需要允许特定的ip您的服务器
  • 是的,之后我更改为较低的安全设置。
  • 也许您需要异步发送电子邮件...您在使用 django-celery 吗? pypi.python.org/pypi/django-celery-email
  • 我没试过,我试试看。感谢您的所有努力。
猜你喜欢
  • 2014-05-27
  • 2016-01-04
  • 2016-06-09
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 1970-01-01
  • 2020-08-04
  • 1970-01-01
相关资源
最近更新 更多