Reputation: 693
I am following this tutorial from digital ocean How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 16.04
Everything is working fine except when I try to send email using gmail it throws 502 bad gateway. nginx log file shows
94 upstream prematurely closed connection while reading response header from upstream
gunicorn configuration
[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 configuration
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;
}
}
Any help will be appreciated.
Upvotes: 2
Views: 1062
Reputation: 1471
I think that error from Nginx is indicating that the connection was closed early before it could complete sending the email. If you are sending emails via gmail, gmail sometimes block the log-in (and sending of emails) from unidentified log-ins or "insecure apps" (that would be the log-in from the server hosting your django application) for security purposes.
You may need to check your gmail security settings to manually ensure that gmail is allowing the web server running your django app (specifically, identify the server i.p.) to send emails.
If that doesn't work you may need to configure DJango to send e-mails asynchronously, see here
Upvotes: 0