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;
        }
相关推荐
Moyu_Friday8 小时前
网络安全基础-计算机网络应用与协议
网络协议·计算机网络
Lsetea8 小时前
curl访问HTTPS报28 Operation timed out:连接超时与总超时分层排查
运维·https·ssl证书·curl·tls
徐同保19 小时前
免费ssl证书全流程AI配置(含七牛云cdn)
网络·网络协议·ssl
Lsetea19 小时前
SSL证书指纹相同但文件哈希不同:PEM、DER与公钥摘要怎么比
运维·https·ssl证书·openssl·证书链
幻智星科技1 天前
一个开源的纯FPGA网口采集卡
网络协议·fpga开发·udp
flash俊杰1 天前
给工具调用划安全红线:SSRF 防护、逐跳复检与沙箱取舍
http
anew___1 天前
《从零手写操作系统 (48):网络协议栈基础——Socket API与TCP/IP分层架构》
网络协议·tcp/ip·架构
TMT星球1 天前
2026阅文创作大会:首批AI精品动画亮相,推出OPC一站式平台与IP委员会模式
人工智能·网络协议·tcp/ip