您可以尝试proxy_pass
而不是return
:
location ~ ^/bproxy/(.*) {
resolver 8.8.8.8; #set DNS resolver (by Google) to prevent "no resolver defined to resolve <domain>" error
proxy_pass http://$1;
}
但是要记住,如果远程页面包含像
<a href="some-path">Link</a>
的某条链路URL成为
http://aproxy.com/bproxy/some-path
和
<a href="/some-path">Link</a>
成为
http://aproxy.com/some-path
也是一样的页内的任何资源(图片,JS,CSS等),所以网页的行为可能会被打破。
也许你应该摆脱/bproxy
路径,并让域aproxy.com
本身成为代理。
更新:
您也可以尝试使用server_name
指令:
server {
listen 127.0.0.1:80;
server_name aproxy.com;
#...
}
更新2 - 服务器代理到特定网站只(不支持HTTPS):
server {
listen 127.0.0.1:80;
server_name aproxy.com;
location/{
resolver 8.8.8.8;
proxy_pass http://stackoverflow.com;
}
}
因此,浏览到http://aproxy.com/questions
,你得到t他相同的结果http://stackoverflow.com/questions
注:
如果你想使这个代理是在本地网络中可见,随着服务器的本地IP取代127.0.0.1
(它可能是这样的192.168.1.10
)
那怎么我是这样开始的,但除非我明确地告诉aproxy.com:80,nginx正在监听0.0.0.0:80 – user340342
我能够将它重定向到正确的URL,但是在该栏中的URL仍然是新网站(www.somewebsite.com),而不是aproxy.com/brpoxy/www.somewebsite.com – user340342
尝试'听n 127.0.0.1:80;'。那么当你在我的文章中浏览具有配置的'http:// aproxy.com/bproxy/stackoverflow.com'时会发生什么? – Curious