My recently configured droplets are exhibiting some unnecessary redirects and I cannot figure out why.
End result should https://domain.com
So I need to rewrite www requests and non-https requests to https without the www.
Currently the opposite is happening, and adding an extra redirect which is costing about an extra 1 second.
So domain.com (307) -> https://domain.com (301) -> https://www.domain.com (200)
My NGINX server blocks looks like this:
server { server_name domain.com www.domain.com; return 301 https://$server_name$request_uri; }
server { listen 443 ssl;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
root /path/to/html;
index index.php;
server_name domain.com www.domain.com;
#additional configurations
}
Some additional information:
Any help would be greatly appreciated. This is the last roadblock to sub-second load times.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Try:
server {
#Redirecting to SSL site
listen 80;
listen [::]:80 ipv6only=on;
server_name domain.com;
location / {
return 301 https://$server_name$request_uri;
}
}
Try removing the additional www.domain.com under listen. If that doesn’t work and redirects don’t work from www.domain.com, add an additional block just for www.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.