http跳转https

1、第一种:不好使

在nginx的配置中,在https的server站点添加如下头部:

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";

这样当第一次以https方式访问我的网站,nginx则会告知客户端的浏览器,以后即便地址栏输入http,也要浏览器改成https来访问我的nginx服务器。

原文链接:https://blog.csdn.net/socho/article/details/72456008

复制代码
server {
        listen       443 ssl;
        listen       [::]:443 ssl;
        server_name  beta.deepcloudsdp.com saas2.deepcloudsdp.com;
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#        ssl on;
        ssl_certificate      /project/redcore/base/nginx/conf/SSL/cert.pem;
        ssl_certificate_key  /project/redcore/base/nginx/conf/SSL/privkey.pem;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

2、第二种

复制代码
server {
        listen       80;
        listen [::]:80;
        server_name  saas2.deepcloudsdp.com;
        rewrite ^(.*)$  https://$host$1 permanent;    # 这行
        #rewrite ^/(.*) https://$server_name/$1 permanent;  # 或这样
        root /project/redcore/webRoot/public;
        index index.html;

        proxy_set_header X-Real-IP $remote_addr;

        location ~* /client/v[345]/push/sse {
           rewrite /client/v[345]/push(.*) $1 break;
           proxy_pass http://172.17.123.5:8181;
           proxy_set_header Connection '';
           proxy_http_version 1.1;
           chunked_transfer_encoding off;
           proxy_buffering off;
           proxy_cache off;
           proxy_read_timeout 600s;
           proxy_connect_timeout 600;
        }
相关推荐
亚林瓜子1 天前
Spring中使用Apache Http客户端调第三方系统接口临时查看请求体参数
spring·http·apache·log
在下村刘湘1 天前
HTTP 请求方式当中GET请求需要请求头吗?
网络·网络协议·http
劉小健1 天前
16-镜像配置-反射镜像
运维·网络·网络协议
jingfeng5141 天前
数据链路层:网络通信的基础与桥梁
网络·网络协议·智能路由器
2501_915921431 天前
Charles 抓包 HTTPS 原理详解,从 CONNECT 到 SSL Proxying、常见问题与真机调试实战(含 Sniffmaster 补充方案)
android·网络协议·小程序·https·uni-app·iphone·ssl
_extraordinary_1 天前
Java HTTP协议(二)--- HTTPS,Tomcat
java·http·https
杨杨杨大侠1 天前
手把手教你写 httpclient 框架(九)- 企业级应用实战
java·http·github
HyperAI超神经1 天前
【TVM 教程】设置 RPC 系统
开发语言·网络·人工智能·python·网络协议·rpc·tvm
xinxinhenmeihao1 天前
HTTP代理HTTP(S)、SOCKS5有哪些作用?
网络·网络协议·http
koping_wu1 天前
【Dubbo】Rpc与HTTP的区别、Dubbo调用过程
http·rpc·dubbo