码迷,mamicode.com
首页 > Web开发 > 详细

NGINX设置http强制跳转https

时间:2020-05-09 17:29:17      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:pac   bsp   多域名   强制   root   php   域名   dev   class   

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
 
 
 

NGINX设置http强制跳转https

标签:pac   bsp   多域名   强制   root   php   域名   dev   class   

原文地址:https://www.cnblogs.com/ccw869476711/p/12858330.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!