Sfwd favicon 152

How To Redirect To Non-www With SSL On Nginx

Posted by Weston Ganger on March 14, 2017

If you ever need to do some redirecting from www to non-www or vice versa with SSL on Nginx you can use the following config


# redirect block
server {
    listen 443 ssl;
    server_name www.example.com;

    ssl_certificate /srv/www/example.com/keys/ssl.crt;
    ssl_certificate_key /srv/www/example.com/keys/example.com.key;
    return 301 https://example.com$request_uri;
}

# ... actual server block ...


Related External Links:


Posted in Web Development and Tagged with nginx ssl 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts