分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

Nginx: http 跳转 https

发布时间:2023-09-06 01:20责任编辑:白小东关键词:http

参考:博文

参考:HTTP 状态码解读

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; ?} 

总结

关于 原博文 在 html 里用 refresh 的方式做跳转的方式我不是很认可,还是把这些事情交给 web server 处理好一些。

Nginx: http 跳转 https

原文地址:http://www.cnblogs.com/tiantiandas/p/nginx_http_to_https.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved