Masking Nginx URLs in Another Domain

There are several similar questions about SO, but none of them are mine, and so far I have not been able to adapt their answers.

I want to map the URL http://sub.example.com to https://123.12.12.12/path so that the browser still displays the URL http://sub.example.com .

My Nginx configuration file looks like

 server { listen 80; server_name sub.example.com; location / { proxy_pass https://123.12.12.12; rewrite ^/$ /path last; } } 

Routing works here, but the URL http://sub.example.com/path displayed. How to make it display only http://sub.example.com ?

+5
source share
1 answer
 server { listen 80; server_name sub.example.com; location / { proxy_pass https://123.12.12.12/path; } } 

Here's how it works. If proxy_pass contains parts of the place, the current location will be replaced with the specified one. http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

But it only helps for http request and http redirect. If the application creates html with links https://123.12.12.12 - it will still remain unchanged. In this case, you can try ngx_http_sub_module.

+18
source

Source: https://habr.com/ru/post/1209870/


All Articles