我试图使用django send_mail函数gmail SMTP在我的Web服务器上发送一封电子邮件,但我得到了502 Bad Gateway错误。
我在使用nginx和gunicorn。
Here is my error.log:
2014/04/12 16:46:55 [error] 26846#0: *11 upstream prematurely closed connection while
reading response header from upstream, client: 179.162.163.62, server: example.com,
request: "POST /contact/ HTTP/1.1", upstream: "http://127.0.0.1:9000/contact/", host:
"example.com", referrer: "http://example.com/contact/"
Ngnix file:
upstream example_gunicorn {
server 127.0.0.1:9000 fail_timeout=0;
server {
listen 80;
client_max_body_size 4G;
server_name .example.com;
keepalive_timeout 5;
location /static/ {
alias /deploy/sites/example/static/; # STATIC_ROOT
expires 30d;
location /media/ {
alias /deploy/sites/example/media/; # MEDIA_ROOT
expires 30d;
location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://example_gunicorn;