Nginx URL masking to a different domain

我的未来我决定 提交于 2019-12-20 12:33:51

问题


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.

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.

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;
    }
}

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?


回答1:


server {
    listen 80;
    server_name sub.example.com;

    location / {
        proxy_pass https://123.12.12.12/path;
    }
}

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

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.



来源:https://stackoverflow.com/questions/27645018/nginx-url-masking-to-a-different-domain

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!