Frage

The traditional way to host multiple websites on a single IP was to use a shared host and use an Apache virtualhost config for each site. Thus different domain names mapped to the different sites based on a virtualhost lookup but they all went to the same IP. However I would like to know:

Is possible to have multiple webservers on a private LAN that can all be accessed on port 80 through a single public facing router/dns/whatever which uses a single public IP.

Ideally the different servers would be accessed by subdomains, such as server1.my-site.com and server2.my-site.com. This is fairly easy to do if your webservers are allowed to serve websites on different ports with port-forwarding, but I need the outside world to not have to know what port to connect on and be able to just input server1.my-domain.com into their browser instead of server1.my-domain.com:1234

This is only an issue due to the increasing scarcity of IPv4 addresses and IPv6 isn't "ready" yet.

War es hilfreich?

Lösung

Yes it is. You have to setup the router as a reverse proxy and forward HTTP requests to one of the hosts in the private network based on the Host header or the request URL. Nginx is a popular choice when it comes to reverse proxying.

If you want to proxy services other than HTTP, SMTP or IMAP servers, then you need to use iptables instead, such as

iptables -t nat -A PREROUTING -d $DOMAIN_NAME -j DNAT --to-destination $SERVER2_IP
iptables -t nat -A POSTROUTING -j MASQUERADE

Andere Tipps

Stefano's solution works only if it is possible to install Nginx on the router. If that is not possible setup reverse proxy (Nginx/Squid/Apache etc.) on a server behind the router. Port forward the traffic from router to the reverse proxy server. Setup reverse proxy to forward the traffic to different servers in the network.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top