Friday, January 9, 2015

ssl - nginx HTTPS WWW redirect to non-WWW

My SSL certificate is for mydomain.com, so i am trying to redirect all www.mydomain.com over to without www. Now, all these work:



http://www.mydomain.com
http://mydomain.com
https://mydomain.com


but https://www.mydomain.com is giving the "Site not safe" warning to the browser...

I tried setting up a redirect like the below but please tell me where my script is buggy...



     server {
listen 80;
server_name www.mydomain.com mydomain.com;
rewrite ^(.*) https://mydomain.com$1 permanent;
client_max_body_size 100M;
location / {
index index.htm index.html index.php;
}


location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/mysite$fastcgi_script_name;
}


}




server {
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/public.crt;
ssl_certificate_key /usr/local/nginx/conf/server.key;



server_name www.mydomain.com;
rewrite ^(.*) https://mydomain.com$1 permanent;

}





server {

listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/public.crt;
ssl_certificate_key /usr/local/nginx/conf/server.key;
client_max_body_size 100M;
server_name mydomain.com;
root /var/www/mysite;
index index.php;

location ~ \.php$ {

include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/mysite$fastcgi_script_name;
}


}

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...