django-allauth: how to modify email confirmation url?

最后都变了- 提交于 2019-11-27 14:07:56

问题


I'm running django on port 8001, while nginx is handling webserver duties on port 80. nginx proxies views and some REST api calls to Django. I'm using django-allauth for user registration/authentication.

When a new user registers, django-allauth sends the user an email with a link to click. Because django is running on port 8001, the link looks like http://machine-hostname:8001/accounts/confirm-email/xxxxxxxxxxxxxx

How can I make the url look like http://www.example.com/accounts/confirm-email/xxxxxxxx ?

Thanks!


回答1:


Django get hostname and port from HTTP headers. Add proxy_set_header Host $http_host; into your nginx configuration before options proxy_pass.




回答2:


I had the same problem, and also found that ferrangb's solution had no effect on outgoing allauth emails. mr_tron's answer got me halfway, but I had to do a little bit more:

1) In nginx configuration, put

proxy_set_header Host $http_host

before options proxy_pass.

2) In settings.py, add the domain name to ALLOWED_HOSTS. I also added the www version of my domain name, since I get traffic to both addresses.

ALLOWED_HOSTS = ['127.0.0.1', 'example.com', 'www.example.com']

And, of course, restart nginx and gunicorn or whatever is serving your Django. With the first step but not the second, all hits to the site were instant 400 errors (unless DEBUG = True in settings.py.)



来源:https://stackoverflow.com/questions/24128433/django-allauth-how-to-modify-email-confirmation-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!