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!
Django get hostname and port from HTTP headers.
Add proxy_set_header Host $http_host;
into your nginx configuration before options proxy_pass
.
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
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With