Unnecessary redirects for HTTPS

Posted February 3, 2016 6k views

My recently configured droplets are exhibiting some unnecessary redirects and I cannot figure out why.

End result should

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 (307) -> (301) -> (200)

My NGINX server blocks looks like this:

server {
return 301 https://$server

server {
listen 443 ssl;

    ssl_certificate /path/to/fullchain.pem;
    ssl_certificate_key /path/to/privkey.pem;

    root /path/to/html;
    index index.php;


    #additional configurations


Some additional information:

  • SSL cert is for both non-www and www
  • A name pointing to IP, with WWW CNAME pointing to
  • Total of 3 sites with the same configuration. Only 1 redirects properly. Incidentally it’s also the only site not currently pointing to Cloudflare DNS. I suspect this might be the source of my issues.

Any help would be greatly appreciated. This is the last roadblock to sub-second load times.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


server {
    #Redirecting to SSL site
    listen 80;
    listen [::]:80 ipv6only=on;

    location / {
      return              301 https://$server_name$request_uri;

Try removing the additional under listen. If that doesn’t work and redirects don’t work from, add an additional block just for www.