nginx 如何只反向代理到网站的二级目录

2018-10-22 20:23:10 +08:00
 jsjcjsjc

我 nas 上 bt 的路径是 olddomain.myqnapcloud.com:60080/rutorrent/ 原来的配置是这样的,这样我访问的时候是 newdomain.com/rutorrent/。但我想把结尾的 rutorrent 去掉

就是访问 newdomain.com ,反向代理到 olddomain.myqnapcloud.com:60080/rutorrent/ 求指点,感谢感谢

server
        {
                listen 80;
                server_name newdomain.com;

                if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
                return  403;
                }

                location / {
                sub_filter olddomain.myqnapcloud.com:60080 newdomain.com;
                sub_filter_once off;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Referer http://olddomain.myqnapcloud.com:60080;
                proxy_set_header Host olddomain.myqnapcloud.com:60080;
                proxy_pass http://olddomain.myqnapcloud.com:60080;
                proxy_set_header Accept-Encoding "";
                }
}
2061 次点击
所在节点    问与答
5 条回复
Tink
2018-10-23 08:43:03 +08:00
二级目录 location 里单独写 auth
Tink
2018-10-23 08:43:26 +08:00
脑子乱了,忽略我
jsjcjsjc
2018-10-23 08:49:52 +08:00
@Tink 哥,别啊~~快清醒清醒
xiaoxinshiwo
2018-10-23 15:29:52 +08:00
jsjcjsjc
2018-10-23 22:28:47 +08:00
@xiaoxinshiwo 确实。。。感谢
```
server
{
listen 80;
server_name new.abc.io;

if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
return 403;
}

location / {
sub_filter olddomain.myqnapcloud.com:60080/rutorrent/ new.abc.io;
sub_filter_once off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer http://olddomain.myqnapcloud.com:60080/rutorrent/;
proxy_set_header Host olddomain.myqnapcloud.com:60080;#此处注意
proxy_pass http://olddomain.myqnapcloud.com:60080/rutorrent/;
proxy_set_header Accept-Encoding "";
}
}
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/499985

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX