nginx將所有http請求重定向至https


轉自:https://www.cnblogs.com/lpjnote/p/10759847.html

 

可以把所有的HTTP請求通過rewrite重寫到HTTPS上

配置

方法一

 server{  
    listen 80;
    server_name XXXXX.com;  //你的域名
if($ssl_protocol = "") {rewrite ^(.*)$ https://XXXXXX.com permanent;} location ~ / { index index.html index.php index.htm;    } }
 

方法二

 server{  
    listen 80;
    server_name XXXXX.com;  //你的域名
    if($ssl_protocol = ""){ return 301 https://$server_name$request_uri;}      
    location ~ / {
    index index.html index.php index.htm;
   }
 }

方法三

 server{  
    listen 80;
    server_name XXXXX.com;  //你的域名
    if($ssl_protocol = ""){rewrite ^(.*)$  https://$host$1 permanent;}      
    location ~ / {
    index index.html index.php index.htm;
  }
}

 

判斷參數ssl_protocol,只要不是https請求的該參數都為空


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM