apache http自动跳转https_NGINX使用rewrite实现http 跳转 https

本文章向大家介绍详解NGINX访问https跳转到http的解决方法,主要包括详解NGINX访问https跳转到http的解决方法使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

关于使用HTTPS/SSL的必要性,可以自行baidu,援引的说法,EFF(Electronic Frontier Foundation),全球过半流量采用https。下面我们介绍使用rewrite 方式实现http 跳转 https。

580c70e0b5bc76fc5ac9f2f7866cecf7.png

Nginx - rewrite 方式

Nginx Server 配置

server {      listen  80;      server_name www.test.com test.com;    rewrite ^(.*)$  https://$host$1 permanent;  } server {      listen       443 ssl;    server_name  www.ourdax.com;       ssl_certificate      /usr/local/openresty/nginx/conf/ssl/test.pem;     ssl_certificate_key  /usr/local/openresty/nginx/conf/ssl/test.key;      root /usr/local/openresty/nginx/html;    index index.html;    location / {          ...    }  }

Nginx - 状态码 497

关于 Nginx 状态码 497

497 - normal request was sent to HTTPS

当此虚拟站点只允许https访问时,当用http访问时nginx会报出497错误码

实现跳转思路

利用 error_page 命令将 497 状态码的链接重定向到指定 URL

Nginx Server 配置

server {      listen       443 ssl;      listen       80;     server_name  www.test.com;       ssl_certificate      /usr/local/openresty/nginx/conf/ssl/test.pem;     ssl_certificate_key  /usr/local/openresty/nginx/conf/ssl/test.key;          root /usr/local/openresty/nginx/html;    index index.html;     location / {            }          error_page 497  https://$host$uri?$args;  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值