nginx配置http访问自动跳转到https

nginx配置http访问自动跳转到https

一般我们的nignx配置ssl的时候

server {
        listen       80;
        listen 443 ssl; 

         ssl_certificate /www/ssl/2097158_wx.wanjiejixie.com.pem;

         ssl_certificate_key /www/ssl/2097158_wx.wanjiejixie.com.key;

         
         root /www/web/wx/public_html;

         server_name  wx.wanjiejixie.com;

      

        index  index.html index.php index.htm;
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  503 /errpage/503.html;
        location ~ \.php$ {
                proxy_pass http://127.0.0.1:88;
                include naproxy.conf;
        }
        location ~ /\.ht {
                deny  all;
        }
        location / {
                try_files $uri @apache;
        }
        location @apache {
                 proxy_pass http://127.0.0.1:88;
                 include naproxy.conf;
        }
}

        
        
        
        

我的ssl证书是这样配置的 但是这种 http的还是可以访问 没有默认到https的站点

那么我们把 两个配置分开


server {
listen 80;
server_name wx.wanjiejixie.com;
rewrite ^(.*) https://$server_name$1 permanent;
}

server {
      
        listen 443 ssl; 

         ssl_certificate /www/ssl/2097158_wx.wanjiejixie.com.pem;

         ssl_certificate_key /www/ssl/2097158_wx.wanjiejixie.com.key;

         
         root /www/web/wx/public_html;

         server_name  wx.wanjiejixie.com;

      

        index  index.html index.php index.htm;
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  503 /errpage/503.html;
        location ~ \.php$ {
                proxy_pass http://127.0.0.1:88;
                include naproxy.conf;
        }
        location ~ /\.ht {
                deny  all;
        }
        location / {
                try_files $uri @apache;
        }
        location @apache {
                 proxy_pass http://127.0.0.1:88;
                 include naproxy.conf;
        }
}

当遇到http访问的时候自动跳转到https的站点 配置完成后 重启nignx

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值