Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

I’m using Gunicorn and Nginx on Ubuntu. I also installed Let’s Encrypt certificates for my example.com and www.example.com with option 2-Redirect to redirect all HTTP to HTTPS.
Now I have the issue that the redirection from www.example.com to example.com is not working properly - it seems to me this happens after I installed Let’s Encrypt certificates (but I’m not exactly sure).
When entering to browser, http://www.example.com/ is redirecting to https://www.example.com/
https://www.example.com/ stays https://www.example.com/
Here is the Nginx configuration:
server {
server_name example.com www.example.com;
location / {
include proxy_params;
proxy_pass http://unix:/run/exampleproject.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name example.com www.example.com;
listen 80;
return 404; # managed by Certbot
}
I’m really not Nginx expert so could you please suggest what to do - how to redirect all www.example.com to example.com and at the same time keep the functionality that HTTP is redirected to HTTPS ?
IMO, probably this part managed by Certbot is doing wrong - it’s just rewriting the whole $host part when redirecting instead of leaving out www:
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
Because this part is related to Gunicorn and I don’t see what could I do here but also I’m very far away of being Gunicorn expert to judge that :-)
location / {
include proxy_params;
proxy_pass http://unix:/run/exampleproject.sock;
}
Thank you !
Edward Sitarski
1fd6b9d2a2b94ee4b3e8ee6d5e2587
Traceurity
fadecomic
Mollie Semmes
Will Walters
f4df2e98b9c74f7eb7f6a0629cf1c4
erel
fingers
fingers