S
S
Sergey2017-08-01 20:59:40
Nginx
Sergey, 2017-08-01 20:59:40

How to redirect multiple locations to different servers?

There is 1 computer with one port to which there is an access from the outside (VPN the client).
This computer is connected to a local network, where there are several computers with their own, rather complex (more than one page), sites (ip and ports are different).
There is a desire to use nginx to watch these sites from the outside. Something like this

http://единственный_ip/one
http://единственный_ip/two

I decided to do it with location
...
location /one {
            proxy_pass http://ipone:portone;
            proxy_set_header X-Real-IP $remote_addr;
        }
location /two {
            proxy_pass http://iptwo:porttwo;
            proxy_set_header X-Real-IP $remote_addr;
        }
...

Naturally, nothing happened, because. "location" is added to the end of the proxy_pass and the result is
http://ipone:portone/one
http://iptwo:porttwo/two

root<->alias - I understand and use within the same computer. But how to "distribute" the network - I will not select a keyword for searching in the documentation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Mukovoz, 2017-08-02
@SergNF

Everything is as easy as shelling pears and even more so already described in the documentation
https://nginx.ru/ru/docs/http/ngx_http_proxy_modul...

location /one/ {
            rewrite    ^/one/$ /$1 break;
            proxy_pass http://ipone:portone;
            proxy_set_header X-Real-IP $remote_addr;
        }
location /two/ {
            rewrite    ^/two./$ /$1 break;
            proxy_pass http://iptwo:porttwo;
            proxy_set_header X-Real-IP $remote_addr;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question