nginx使用子目录反向代理https域名
目标原始地址:
https://test-open.myrunners.com/oauth2/login?client_id=km1fzxal08ysh935oiurpdtv&redirect_uri=http://www.abc.com/runTeamH5/pages/punch_card/punch_card_index.html&state=run_team
现在要实现用下面这个地址也可以访问:
http://123.abc.com/run_team_web/oauth2/login?client_id=km1fzxal08ysh935oiurpdtv&redirect_uri=http://www.abc.com/runTeamH5/pages/punch_card/punch_card_index.html&state=run_team
即使用http://123.abc.com/run_team_web这个地址来反向代理https://test-open.myrunners.com地址,实现方法如下:
location ~ ^/run_team_web(/?)(.*){
include deny.conf;
rewrite /run_team_web/(.*) /$1 break; #如果是子目录需设置正则
rewrite ^/run_team_web$ /run_team_web/ permanent;
proxy_redirect off;
proxy_set_header Host "test-open.myrunners.com";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://223.111.8.117;
error_log logs/run_team_web_error.log info;
access_log logs/run_team_web_access.log main;
}
reload nginx即可实现;
里面的proxy_pass直接写IP、proxy_set_header Host写域名是为了能代理到https协议,要么nginx会报错
2017/11/07 10:36:26 [error] 9304#0: *215130049 SSL_do_handshake() failed (SSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol) while SSL handshaking to upstream, client: 192.168.120.153, server: www.abc.com, request: "GET /run_team_web/oauth2/login?client_id=km1fzxal08ysh935oiurpdtv&redirect_uri=http://www.abc.com/runTeamH5/pages/punch_card/punch_card_index.html&state=run_team HTTP/1.1", upstream: "https://223.111.8.117:80/run_team_web/oauth2/login?client_id=km1fzxal08ysh935oiurpdtv&redirect_uri=http://123.abc.com/runTeamH5/pages/punch_card/punch_card_index.html&state=run_team", host: "123.abc.com"
Tag标签:「nginx 域名 https 反向 代理」更新时间:「2021-11-04 17:28:24」阅读次数:「921」