Community discussions

MikroTik App
 
antoncd
just joined
Topic Author
Posts: 17
Joined: Tue Jul 30, 2019 10:35 am

NAT redirect depending on host name

Mon Jan 31, 2022 6:19 pm

I have a Mikrotik router. Currently I have several NAT rules routing from requests to the Router exposed IP and specific routes to specific IPs within my network and specific ports.

123.123.123.123:4001 => 192.168.0.2:4001
123.123.123.123:4002 => 192.168.0.2:4002
123.123.123.123:4003 => 192.168.0.2:4003

I want to do the same, but with domain names without the ports. Is that possible?
Untitled Diagram.drawio.png
You do not have the required permissions to view the files attached to this post.
 
tangent
Forum Guru
Forum Guru
Posts: 1351
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: NAT redirect depending on host name

Mon Jan 31, 2022 6:32 pm

What protocol?

With HTTP, what you’ve diagrammed is called name-based virtual hosting, which many HTTP servers can do. (But not all.)

If you mean some other protocol, the answer will differ.

It’s the application protocol that does this, necessarily so. NAT is too low level to even see DNS names.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10195
Joined: Mon Jun 08, 2015 12:09 pm

Re: NAT redirect depending on host name

Mon Jan 31, 2022 6:41 pm

I want to do the same, but with domain names without the ports. Is that possible?
No, that is not possible. At least not in a NAT rule.
It is possible in a "reverse proxy". You need to install that on your server, as MikroTik does not have one.
 
antoncd
just joined
Topic Author
Posts: 17
Joined: Tue Jul 30, 2019 10:35 am

Re: NAT redirect depending on host name

Mon Jan 31, 2022 6:43 pm

Sorry, http and https.
With HTTP, what you’ve diagrammed is called name-based virtual hosting, which many HTTP servers can do. (But not all.)
But this is not handled by the router, right?


I also realized that there may be a simpler solution. Instead of having the router handling the work of routing domains to IPs and ports, I may just redirect all requests to port 80 to a web proxy as Nginx. Then Nginx would redirect based on host name. My concern is that this proxy would be a bottleneck. My plan would be to set up a Raspberry pi to handle this task alone.
Untitled Diagram(1).jpg
You do not have the required permissions to view the files attached to this post.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10195
Joined: Mon Jun 08, 2015 12:09 pm

Re: NAT redirect depending on host name

Mon Jan 31, 2022 7:03 pm

I also realized that there may be a simpler solution. Instead of having the router handling the work of routing domains to IPs and ports, I may just redirect all requests to port 80 to a web proxy as Nginx. Then Nginx would redirect based on host name. My concern is that this proxy would be a bottleneck. My plan would be to set up a Raspberry pi to handle this task alone.
You can install it on the web host itself (192.168.0.3)
 
tangent
Forum Guru
Forum Guru
Posts: 1351
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: NAT redirect depending on host name

Mon Jan 31, 2022 7:17 pm

But this is not handled by the router, right?

Indeed not. You set things up to forward ports 80 and 443 to the internal machine for all HTTP/HTTPS accesses, and then configure the web server to respond differently depending on what name it was called by for each individual request.

This is ancient (1997) tech, now widely supported. It goes back to HTTP/1.1, being one of the things added relative to the now totally obsolete HTTP/1.0. About the only things doing HTTP/1.0 now are people hand-typing the protocol, tiny embedded systems, and badly outdated code frozen in time for the past two decades.

web proxy...Nginx...redirect based on host name.

Or, just make it your web server, period, full stop. Note the "server_name" directive in its virtual host configuration docs. You can set up as many of those as you need. My public nginx server responds to half a dozen different names.

If you have to do reverse proxying atop that, fine, but for static hosting, you don't need to go to that extent.

Who is online

Users browsing this forum: No registered users and 15 guests