NGINX設置http強制跳轉https


NGINX設置http強制跳轉https

 

 

方法一:

打開nginx.conf或虛擬機配置文件

server {
     listen 80;
     server_name dev.wangshibo.com;
     index index.html index.php index.htm;
   
     access_log  /usr/local/nginx/logs/8080-access .log main;
     error_log  /usr/local/nginx/logs/8080-error .log;
     
     if ($host = "dev.wangshibo.com" ) {
        rewrite ^/(.*)$ http: //dev .wangshibo.com permanent;
     }
 
     location ~ / {
     root /var/www/html/8080 ;
     index index.html index.php index.htm;
     }
     }
 
 

 

方法二:這種方式適用於多域名的時候,即訪問wangshibo.com的http也會強制跳轉到https://dev.wangshibo.com上面

打開nginx.conf或虛擬機配置文件

server {
     listen 80;
     server_name dev.wangshibo.com wangshibo.com *.wangshibo.com;
     index index.html index.php index.htm;
   
     access_log  /usr/local/nginx/logs/8080-access .log main;
     error_log  /usr/local/nginx/logs/8080-error .log;
     
     if ($host ~* "^wangshibo.com$" ) {
     rewrite ^/(.*)$ https: //dev .wangshibo.com/ permanent;
     }
  
     location ~ / {
     root /var/www/html/8080 ;
     index index.html index.php index.htm;
     }
     }
 
 
 
資料來源:https://www.cnblogs.com/kevingrace/p/6187072.html
 
 
 


免責聲明!

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



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