✓ Solved
Django send_mail with 502 Bad Gateway
I have a contact form on my django based website and the form uses django smtp mail backend with smtp.gmail.com settings.
There was no problem with development server DEBUG=True but with production DEBUG=False, when I try to send contact form, it returns with 502 Bad Gateway error.
sudo tail -F /var/log/nginx/error.log
2022/02/20 17:48:38 [error] 1342#1342: *88 upstream prematurely closed connection while reading response header from upstream, client: 176.42.21.164, server: burcuatak.com, request: "POST /contact/ HTTP/1.1", upstream: "http://unix:/home/user/project/project.sock:/contact/", host: "burcuatak.com", referrer: "https://burcuatak.com/contact/"
/etc/nginx/sites-available/project
server {
server_name burcuatak.com www.burcuatak.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/user/project;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/user/project/project.sock;
}
}
server {
if ($host = www.burcuatak.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = burcuatak.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name burcuatak.com www.burcuatak.com;
return 404; # managed by Certbot
2 Replies
✓ Best Answer
Are the mail ports open for your Linode?
On new Linodes, ports 25, 465 and 587 are blocked until you ask Linode support to open them. You need to file a support ticket about this.
-- sw