Nginx redirect http://www and naked http/https to https://www

前端 未结 4 1024
暖寄归人
暖寄归人 2021-01-02 12:16

I would like to redirect all traffic from the following domains:

  • http://domain.com
  • http://www.domain.com
  • http
4条回答
  •  盖世英雄少女心
    2021-01-02 12:59

    Following will help.

    server {
                listen 80;
                listen [::]:80;
                server_name example.com www.example.com;
    
    
                return 301 https://www.example.com$request_uri;
        }
    
      server {
                listen 443 ssl http2;
                listen [::]:443 ssl http2;
                server_name example.com;
                return 301 https://www.example.com$request_uri;
       }
    
    server {
                listen 443 ssl http2;
                listen [::]:443 ssl http2;
                server_name www.example.com;
    
       ====>>> Your site configuratioin Goes here <<======
    }
    

提交回复
热议问题