nginx url rewrite with www and none www

ssl + adds www
return 301 https://www.$host$request_uri;
this redirect makes all https
return 301 https://$host$request_uri;

Full Config with this example

 

server {
listen 80 default_server;

return 301 https://www.$host$request_uri;

root /usr/share/nginx/html;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

}
server {
listen 443 ssl;
server_name localhost;
ssl on;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

ssl_certificate /etc/nginx/ssl/sant.crt; #you have to put here…
ssl_certificate_key /etc/nginx/ssl/san.key; # …paths to your certificate files
return 301 https://www.$host$request_uri;
}

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s