Deprecated: Creation of dynamic property Typecho\Widget\Request::$feed is deprecated in /www/wwwroot/blog.iletter.top/var/Widget/Archive.php on line 253
白荼日记 - 运维 2025-08-26T12:19:00+08:00 Typecho https://blog.iletter.top/feed/atom/tag/%E8%BF%90%E7%BB%B4/ <![CDATA[https嵌套http(修改安全策略)]]> https://blog.iletter.top/archives/455/ 2025-08-26T12:19:00+08:00 2025-08-26T12:19:00+08:00 DelLevin https://blog.iletter.top 因为需要用到https嵌套http,但是这怎么可能啊?还好那个http有https的协议,所以我们只需要再nginx上操作升级CSP就行了。也就是内容安全策略。

HTTPS页面 (aaa.com)
└── HTTP iframe (bbb.com)
    └── HTTP frame (ccc.com)

大概是这种形式的,所以在第一个a网站是我自己写的,所以我就选择了直接使用http替换成https的了

然后配置b网站

server {
    listen 80;
    server_name www.bbb.com;
    
    # 强制跳转到 HTTPS
    return 301 https://$host$request_uri;
}

# 处理www.bbb.com 的 HTTPS 请求
server {
    listen 443 ssl;
    server_name www.bbb.com;
    
    # SSL 证书配置(你需要配置自己的证书)
    ssl_certificate /path/to/your/certificate.crt;
    ssl_certificate_key /path/to/your/private.key;
    
    # 添加安全头
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header Content-Security-Policy "upgrade-insecure-requests";
    
    # 代理到后端应用
    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    
    # 特别处理企业查看接口,确保内容中的HTTP链接被替换
    location /rotech-xyjq-api/api/enterprise/view {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # 替换内容中的HTTP链接为HTTPS
        sub_filter 'http://b-plugin.qixin.com/' 'https://b-plugin.qixin.com/';
        sub_filter 'http://b-plugin.qixin.com' 'https://b-plugin.qixin.com';
        sub_filter_once off;
    }
}

这样就可以再a网站加载c网站的了,可以无限套娃了,前提是每个娃娃都有https这个。

]]>