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

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

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

原文来自:https://www.cnblogs.com/tiantiandas/p/nginx_http_to_https.html

本文地址:https://www.linuxprobe.com/nginx-http-https.html编辑:问题终结者,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/