无法使用django和nginx(gunicorn)在数字海洋水滴上发送电子邮件

问题描述 投票:1回答:1

我在ubuntu Droplet上使用django + nginx + gunicorn部署了一个网站。我使用django的电子邮件功能。但是,每次我尝试发送电子邮件时,我的网站都出现了502错误。

我的nginx错误日志是:

[error] 24933#24933: *30944 upstream prematurely closed connection while reading response header from upstream, 
client: 45.34.23.99, server: server.cn
request: "GET /confirmation-email-send/3/ HTTP/1.1", upstream: "http://unix:/tmp/server.cn.socket:/confirmation-email-send/3/",
host: "server.cn", referrer: "https://server.cn/signup/contestant"

django中的Settings.py:

EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.sina.com'
EMAIL_HOST_USER = '****@sina.com'
EMAIL_HOST_PASSWORD = '****'
EMAIL_PORT = 465
EMAIL_FROM = '****[email protected]'

/etc/Nginx/sites-available/server.才能:

server{
charset utf-8;
listen 80;
listen 465;
server_name server.cn;

location /static {
    alias /path/to/static;
}

location / {
    proxy_set_header Host $host;
    proxy_pass http://unix:/tmp/server.cn.socket;
}

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/server.cn/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/server.cn/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


if ($scheme != "https") {
    return 301 https://$host$request_uri;
} # managed by Certbot

}

当我在localhost运行网站时,发送电子邮件的功能很好。所以我认为问题在于部署。

我见过一些类似的问题,但提供的方法无法解决我的问题。

django email nginx gunicorn
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.