Nginx URL屏蔽到另一个域
关于SO,也有一些类似的问题,但没有一个完全是我的,到目前为止,我还没有尝试改编他们的答案的运气.
There's a few similar questions on SO, but none exactly mine, and I've had no luck trying to adapt their answers so far.
我想将URL http://sub.example.com
映射到https://123.12.12.12/path
,以便浏览器仍显示URL http://sub.example.com
.
I want to map the URL http://sub.example.com
to https://123.12.12.12/path
, such that the browser still shows the URL http://sub.example.com
.
我的Nginx配置文件看起来像
My Nginx config file looks like,
server {
listen 80;
server_name sub.example.com;
location / {
proxy_pass https://123.12.12.12;
rewrite ^/$ /path last;
}
}
路由在这里起作用,但是显示的URL是http://sub.example.com/path
.如何使其仅显示http://sub.example.com
?
The routing works here, but the URL displayed is http://sub.example.com/path
. How do I make it display only http://sub.example.com
?
server {
listen 80;
server_name sub.example.com;
location / {
proxy_pass https://123.12.12.12/path;
}
}
这就是它的工作方式.如果proxy_pass包含部分位置-当前位置将替换为指定位置. http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Thats how it works. If proxy_pass contains locations part - current location will be replaced to specified. http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
但这仅对http请求和http重定向有用.如果应用程序使用链接https://123.12.12.12
创建html-它仍然保持不变.在这种情况下,您可以尝试使用ngx_http_sub_module.
But it's help only for http request and http redirects. If application create html with links https://123.12.12.12
- it's still unchanged. In this case you can try ngx_http_sub_module.