夹层联系表产生 "upstream prematurely closed" 错误

Mezzanine contact form produces "upstream prematurely closed" error

我的网站使用 Mezzanine 4.2.3 与 Django-Oscar 1.5.2 和 Django 1.10.8,运行 在 Ubuntu 16.04 on Digitalocean。当我在使用 createdb 创建的演示页面上使用 Mezzanine 联系表并从我自己的计算机上时,它成功地发送了电子邮件。但是当我在我的 Digitalocean droplet 运行 Ubuntu 16.04 上测试它时,我得到 502 bad gateway.

nginx 错误日志记录了这个错误:*13 upstream prematurely closed connection while reading response header from upstream, client: [an IP I can't identify], server: [my website url], request: "POST /contact/ HTTP/1.1", upstream: "http://unix:/home/my-django-app/my-django-app.sock:/contact/", host: "[my website url]", referrer: "[my website url]/contact/"*1*7*13 之间的数字有所不同,但文本是相同的。

我用谷歌搜索并找到了各种可能的解决方案:

nginx 侦听端口 587,sudo netstat -tulnp | grep 587 显示:

tcp        0      0 0.0.0.0:587             0.0.0.0:*               LISTEN      12815/nginx -g daem

我的电子邮件设置似乎没问题:

EMAIL_USE_TLS = True
EMAIL_HOST = "smtp.gmail.com"
EMAIL_HOST_USER = "!#%%&&*%^#$^*%@gmail.com"
EMAIL_HOST_PASSWORD = "^*#^@#$%&@$%%#$"
EMAIL_PORT = 587
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

我也尝试过使用 465 端口的 SSL。它适用于我的本地副本,但不适用于服务器。同样的错误信息 502.

我认为"upstream"是gunicorn的意思,所以我给它设置了一个错误日志,但是它记录的都是页面加载时的状态码200和302。当 502 发生时它没有记录任何内容。

我没主意了。我错过了什么?

2018 年 6 月 3 日更新:

$ telnet smtp.gmail.com 587
Trying 108.177.96.109...
Trying 108.177.96.108...
Trying 2a00:1450:4013:c01::6c...
telnet: Unable to connect to remote host: Network is unreachable

也用 465 和 25 试过了。这是否意味着 Digitalocean 正在阻止连接?有 precedent.

是的,Digitalocean 阻止了 SMTP。他们回复我的电子邮件:

To assist with the restriction of SMTP services on your account, can you please let us know the following:

  1. Your name.
  2. What business or individual you are going to send mail on behalf of as well as their website (if one exists).
  3. What kind of mail you're going to be sending (password resets, newsletters, marketing mail, transactional mail such as order confirmations).
  4. If you're sending on behalf of a business or an individual that is not yourself, what is your relationship to that business or individual.

Also, as we are a US based company, I'd like to make sure you understand that we require all users of our network to follow both the requirements of the CAN-SPAM ( https://www.ftc.gov/tips-advice/business-center/guidance/can-spam-act-compliance-guide-business )act in regards to any non-transactional mail sent to any subscriber anywhere in the world, as well as the CASL ( http://fightspam.gc.ca/eic/site/030.nsf/eng/home ) for any email you send to any subscribers in Canada.

Additionally, there are additional restrictions to sending email to users in Europe created by both the EU itself and its member countries, and would recommend that you investigate and follow all relevant guidelines for the countries of any European subscribers you may have.

我回答了他们,他们回答:

Thank you for the information you have provided.

We've reviewed the information and have removed the SMTP block from your account.

Just to reiterate - we require our subscribers to follow the CAN-SPAM act for all email, and the CASL for any email sent to a subscriber in Canada.

If you do not, and we receive complaints of violations, we can revoke access to SMTP at our discretion with no further warning.