Answer the question
In order to leave comments, you need to log in
How to configure Nginx reverse proxy for all ports?
The situation is as follows:
* one physical server with a dedicated IP
* several virtual machines
It is necessary:
* depending on the domain, proxy all ports to a specific virtual machine (that is, example1.com:22 will go to the first virtual machine, and example2.com:22 to the second one)
* proxying must be invisible to the virtual machine (remote addr and the like) so that it seems to it that it is looking into the world directly.
Search basically gives a solution for other kinds of problems.
If I'm wrong about something - please correct me, the main thing is to solve the problem.
Answer the question
In order to leave comments, you need to log in
With such statement of the problem it is not solved.
Since in fact, not virtual machines are used, but Docker containers - I decided using reverse proxy for http / https, binding to other ssh ports of containers where it is, and dedicated IP for more complex situations.
It seems that it will not be possible to automatically proxy all ports. For each port, you will need to write lines in the config separately. For your example, you'll need something like this:
server {
listen 22;
server_name example1.com;
location / {
proxy_pass http://192.168.1.1:22;
}
}
server {
listen 22;
server_name example2.com;
location / {
proxy_pass http://192.168.1.2:22;
}
}
GET / HTTP/1.0
Host: example1.com
In this formulation, the problem is not solved in principle.
Firstly, nginx is an http/mail server and cannot proxy any protocol. (Perhaps someone wrote a module for balancing MySQL, but it's still another special case of the protocol, and not any protocol).
Secondly, the concept of a domain exists only in http, and in the same ssh the client connects via an IP:port pair and does not transmit any additional data.
Thirdly, why all this? Usually it is enough to proxy http (definition by domains works fine here) and forwarding ssh with separation by ports.
nginx is not able to proxy your ssx
, and in general, no one can proxy ssx by domain, since the domain is most likely not transferred in it.
buy IPs and give them to each virtual machine, it costs every penny.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question