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;
        }
相关推荐
Hello_Embed8 小时前
嵌入式上位机开发入门(二十六):将 MQTT 测试程序加入 APP 任务
网络·笔记·网络协议·tcp/ip·嵌入式
IpdataCloud12 小时前
IP查询高精度怎么选?8个指标判断是否适合你
网络·网络协议·tcp/ip
聊点儿技术12 小时前
IP风险等级评估是什么?跨境电商业务场景全解析
网络·网络协议·tcp/ip
路溪非溪13 小时前
网络运输层:TCP协议详解(一)
网络·网络协议·tcp/ip
困惑阿三15 小时前
Nginx 域名绑定与 HTTPS 配置指南
运维·nginx·https·ssl
凯勒姆15 小时前
主流网络协议
网络·网络协议
郝学胜-神的一滴15 小时前
Linux 高并发基石:epoll 核心原理 + LT/ET 触发模式深度剖析
linux·运维·服务器·开发语言·c++·网络协议
treesforest16 小时前
Ipdatacloud IP 地址查询方案适合哪些场景?
大数据·网络·数据库·网络协议·tcp/ip·ip
追兮兮16 小时前
基于 GD32 与 LwIP 的 TCP OTA 固件升级实现
网络·网络协议·tcp/ip·tcp·gd32·ota
Hello_Embed17 小时前
嵌入式上位机开发入门(二十八):JSON 与 JsonRPC 入门
网络·笔记·网络协议·tcp/ip·嵌入式