Nginx实现 内网访问外网https页面资源的解决方案
在开发过程中,有遇到在内网环境下需要访问外网https页面。遇到这个需求也是比较不好做。经过查询资料和调试最终完成功能。
·
项目场景:
在开发过程中,有遇到在内网环境下 需要访问外网 https页面。遇到这个需求也是比较不好做。经过查询资料和调试最终完成功能。
问题描述
解决思路 : 通过 nginx 反向代理来实现
原因分析:
因为需要访问的https页面,所以不能直接配置 http相关参数。需要将nginx代理端口换成https方式
配置如下:
server {
listen 8081 ssl; # 443端口
server_name yhpm.pmsaas.net; # 你的域名
# 你的域名下申请的证书
ssl_certificate ../cert/xxx.crt; # 外网的https的安全证书
ssl_certificate_key ../cert/xxxx.key; # 外网的https的安全证书
# 默认按此配置
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
# 默认按此配置
ssl_protocols TLSv1.2 TLSv1.3;
# 默认按此配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
# 这里是请求后台的API,我这里以 / 开头
location / {
add_header Content-Security-Policy upgrade-insecure-requests; #这里这个就是处理https反向代理http时候静态资源的关键
# 反向代理 服务
proxy_pass https://xxxx.net;
}
# 加载静态资源 必加,不然样式会加载不到
location ~ .*\.(js|css)$ {
proxy_pass https://xxxx.net;
}
# 加载静态资源 必加,不然样式会加载不到
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
proxy_pass https://xxxx.net;
expires 30d;
error_log off;
access_log off;
break;
}
# error config
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
解决方案:
上述就是解决 内网访问外网 https页面的具体步骤。
更多推荐
已为社区贡献5条内容
所有评论(0)