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;
        }
相关推荐
喵个咪2 小时前
Go-Wind HTTP 服务器从入门到精通
后端·http·go
不做菜鸟的网工2 天前
BGP特性
网络协议
AlfredZhao2 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
明月_清风4 天前
开发者网络概念全扫盲:一篇搞定
后端·网络协议
刘马想放假4 天前
Modbus 全栈技术解析:TCP、RTU、ASCII、RTU over TCP
数据结构·网络协议
王二端茶倒水5 天前
一套可落地的无线运营方案,不能只管 AP,还要管用户、计费和运维
网络协议
162723816085 天前
EtherCAT 分布式时钟(DC)原理与配置实战:把多轴真正"对齐到同一时刻"
网络协议
王二端茶倒水6 天前
宽带无线项目,怎么从一次性交付变成长期运营收入?
网络协议
Goodbye6 天前
大模型无状态架构:从 HTTP 协议到 Harness AI 工程的深度解析
http