Nginx redirect Http to Https - what's wrong here?

后端 未结 2 697
既然无缘
既然无缘 2020-12-21 04:13

I have an Nginx server which should redirect all requests from http://www.domain.com and http://domain.com and https://domain.com to https://www.domain.com

So with o

2条回答
  •  遥遥无期
    2020-12-21 05:08

    The most nice way that I found looks like:

    server {
            listen 80;
            server_name example.com www.example.com;
            return 301 https://$server_name$request_uri;
    }
    
    server {
        listen       443 ssl;
        server_name  examle.com www.example.com;
    
        ssl_certificate /etc/nginx/conf.d/[crt];
        ssl_certificate_key /etc/nginx/conf.d/[key];
        ... 
    }
    

    In this way you can use $server_name instead of hardcoded values.

提交回复
热议问题