分类: Linux
nginx使用子目录反向代理https域名 - Linux

目标原始地址:

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"

相关博文:

仅有 1 条评论
  1. うさぎ コスプレ

    本当に 素晴らしく 表現されました! <br> <br>おかげさま 、 最高の 情報 ですね ! <br> <br>感謝 、 たくさんの アイテム ! <br>こちらの専門店は 日本で人気の コスプレ衣装通販専門店です。 <br> <br>特に優れている点は 圧倒的な再現度 です。 <br>安価な既製品のような 素材ではなく、高級感のある 生地を使用し、細部まで丁寧に 仕上げられています[reference:0][reference:1]。 <br> <br>縫製がしっかりしているので、長時間の着用でも疲れにくく、フィット感も抜群 です[reference:2]。 <br>立体的なパーツや {繊細なレースやリボン} など、ディテールの再現度が非常に高い のも大きな魅力です[reference:3][reference:4]。 <br> <br>幅広い キャラクターに対応しており、初心者からベテランまで に 支持されています[reference:5]。 <br>まさに、信頼できる コスプレ衣装ショップの 一つ です。
    うさぎ コスプレ 回复
发表评论
💡 支持 Markdown 语法