Toggle navigation
主页
文章
ChatGPT
在线编程
pygame-ide-online
关于
登录
注册
文章
用户
相关用户
查看全部>
兜兜
文章 206
勒布朗陈佩
...
斯2
文章 1
海婧忆豚
文章 3
admin
...
istrator
文章 1
大王山
文章 2
不想差那么
...
一点
文章 0
EllJu
...
rb
文章 0
32325
...
23532
文章 0
文章类别:
Web开发 (0)
云计算 (0)
大数据 (5)
区块链 (0)
安全 (4)
数据库 (9)
服务器 (9)
架构 (1)
游戏开发 (0)
物联网 (0)
移动开发 (0)
系统 (7)
运维 (38)
编程语言 (10)
网络 (4)
计算机基础 (0)
软件研发 (0)
其他 (0)
原创
阿里云SLB+nginx+tomcat HTTPS配置
兜兜
2018-08-09 15:07:32
2020-03-08 18:41:51
nginx
https
X-Forwarded-Proto
scheme
#### **nginx+tomcat** nginx配置: ```bash proxy_set_header Host $host; proxy_set_header Cookie $http_cookie; 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; proxy_pass http://127.0.0.1:8181; ``` tomcat配置: ```xml <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" internalProxies="172\.16.\d{1,3}\.\d{1,3}" #注意坑:如果使用tomcat7,并且内网ip是172网段需要加上internalProxies, 官网解释:http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html protocolHeaderHttpsValue="https"/> ``` internalProxies参考:http://blog.inford.net/doc/171 #### **阿里云SLB+nginx+tomcat** 阿里云SLB配置:  nginx配置: ```bash proxy_set_header Host $host; proxy_set_header Cookie $http_cookie; 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 $http_x_forwarded_proto; #http_x_forwarded_proto参数为SLB传过来的参数 proxy_pass http://127.0.0.1:8181; ``` tomcat配置: ```xml <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" protocolHeader="X-Forwarded-Proto" protocolHeaderHttpsValue="https"/> ``` #### 上面的配置,一般的访问没有问题,当页面发生302重定向会请求http的问题,出现 requested an insecure XMLHttpRequest nginx配置(nginx+tomcat) ```bash proxy_redirect http:// $scheme://; #302重定向请求的http协议转发到$scheme ``` nginx配置(阿里云SLB+nginx+tomcat) ```bash proxy_redirect http:// $http_x_forwarded_proto://; #302重定向请求的http协议转发到$http_x_forwarded_proto ```
阅读 2680
评论 0
收藏 0
阅读 2680
评论 0
收藏 0