全球主机交流论坛

标题: nginx反向代理的疑问 [打印本页]

作者: xshell    时间: 2020-12-19 11:39
标题: nginx反向代理的疑问
我们平时反向代理都是域名的根目录,既 abc.com

如果我要反向到其他目录应该怎么操作,如 123.com反代到abc.com/efg/

按原来的反向代理操作的话,我反代的只是源站的123.com/efg/的目录,如何做到访问abc.com/efg/就是123.com而不是123.com/efg/
作者: 送财童子小花花    时间: 2020-12-19 11:41
    location ~ \mulu{
        你的反带代码;
    }
小花花沙发马克任务(534/999)

作者: rooney    时间: 2020-12-19 11:43
本帖最后由 rooney 于 2020-12-19 11:44 编辑

身体失误,当我什么都没说
作者: xshell    时间: 2020-12-19 11:50
送财童子小花花 发表于 2020-12-19 11:41
location ~ \mulu{
        你的反带代码;
    }

光这样就行了嘛?
作者: 送财童子小花花    时间: 2020-12-19 11:54
xshell 发表于 2020-12-19 11:50
光这样就行了嘛?

那不然咧,这个简单的就能解决你的问题呀
在一个location里才跑反向代理的代码,就是你的需求啦

作者: Icarus    时间: 2020-12-19 12:01
location 和 proxy_pass 设置好随便搞
作者: liuyangge    时间: 2020-12-19 12:47
rewrite+bypass可以实现  下面示例 实现了访问 域名/tz 实际指向为 http://172.0.0.10:80/index.php
  1. location ~ ^/tz {
  2.       rewrite  ^(.*)$  /index.php$1;break;
  3.       proxy_pass http://172.0.0.10:80;
  4.     }
复制代码

作者: xshell    时间: 2020-12-19 19:57
liuyangge 发表于 2020-12-19 12:47
rewrite+bypass可以实现  下面示例 实现了访问 域名/tz 实际指向为 http://172.0.0.10:80/index.php:lo ...

这样只有index.php才能访问啊 其他都4040
作者: liuyangge    时间: 2020-12-19 20:18
xshell 发表于 2020-12-19 19:57
这样只有index.php才能访问啊 其他都4040

要学会变通啊
作者: xshell    时间: 2020-12-19 21:10
liuyangge 发表于 2020-12-19 20:18
要学会变通啊

每一个页面都这样弄一下?
作者: liuyangge    时间: 2020-12-19 21:22
xshell 发表于 2020-12-19 21:10
每一个页面都这样弄一下?

你可以location正则匹配 然后取$uri变量rewrite到对应地址 然后proxy_pass
作者: xshell    时间: 2020-12-19 21:27
liuyangge 发表于 2020-12-19 21:22
你可以location正则匹配 然后取$uri变量rewrite到对应地址 然后proxy_pass

大佬可以写一下吗?真的不会
作者: liuyangge    时间: 2020-12-19 21:36
xshell 发表于 2020-12-19 21:27
大佬可以写一下吗?真的不会

你给两个示例啊  我帮你看一下怎么写
作者: xshell    时间: 2020-12-19 21:50
liuyangge 发表于 2020-12-19 21:36
你给两个示例啊  我帮你看一下怎么写

就是把某个网站例如  abc.com   反代到我的网站目录    XXX.com/abc/  

然后XXX.com/abc/可以正常访问abc.com的全部内容
作者: liuyangge    时间: 2020-12-19 22:42
xshell 发表于 2020-12-19 21:50
就是把某个网站例如  abc.com   反代到我的网站目录    XXX.com/abc/  

然后XXX.com/abc/可以正常访问ab ...
  1. location ~ ^/abc/(.*) {
  2.       rewrite ^/abc/(.*)$ /$1;break;
  3.       proxy_pass http://abc.com;
  4.     }
复制代码


作者: xshell    时间: 2020-12-19 22:54
liuyangge 发表于 2020-12-19 22:42

感谢大佬 可以了




欢迎光临 全球主机交流论坛 (https://loc.998820.xyz/) Powered by Discuz! X3.4