Apache Virtual host

Good day. I’ve read a lot of articles on the topic of virtual hosts in Apache, but I don’t quite understand what the configuration should be if the content of the second virtual host is located on another host. For example:
There is a domain: example.com
Third level domain: forum.example.com
Domain website: example.com whose IP address is
Domain website: forum.example.com IP address is
The main domain is example.com, how can I set up an Apache virtual host so that when requests come to the forum.example.com, Apache redirects all traffic to Or is there another solution?

You usually tend to use vhosts if both domains are pointing to the same server. In your instance, all you need is Apache configured on both servers ( and DNS already knows where each of the domains are, so as long as Apache is running and configured to load the website or the forum, then it will be OK.

If you had both example.com and forum.example.com on the same server, eg: - then you would configure vhosts in the Apache config to make sure it redirects to the correct location for the website directory, eg: /var/www/website or /var/www/forum.

But as I said, for your instance, you don’t need vhosts, as you have both domains pointing to different servers. You just need apache running on both servers, configured to serve the website on, and the forum on

Yes, I have done it exactly as you wrote. But what then to do with the external IP address? For example:
External IP to which the example.com domain is linked and all requests that come to this domain are redirected through the router to the internal network to the address External IP and internal IP use port 80.
The domain forum.example.com also points to the external IP address, but how can I route requests coming to port 80 to this domain to the internal network to the address My router cannot use two 80 ports on the external IP. I don’t understand how two domains (example.com and forum.example.com) tied to one external IP address and running on the same port (80) can be divided into two servers on the internal network.

Yes, so you can only NAT from the public IP to a single IP for ports 80 or 443. So you will have to use same server for both example.com and forum.example.com - eg: put both on

Examples of vhost config: apache virtual host example - Google Search

You could use mod_proxy in Apache to forward requests to the other host.

Aaaaaaaaaaaaaaa virtual host points to different sites but on the same server. I don’t have the option to move everything to one server. What other way can this problem be solved?

How is that? If it’s not difficult, could you briefly explain it to me?

It’s been a while since I’ve set it up and I no longer have access to those servers, but it’s all in the Apache documentation [mod_proxy - Apache HTTP Server Version 2.4]

Would it be something like

<VirtualHost forum.example.com:80>
  RewriteEngine on
  ProxyPass ""
  ProxyPassReverse ""

<VirtualHost example.com:80>
  RewriteEngine on
  ProxyPass ""
  ProxyPassReverse ""

in /etc/httpd/conf.d/00-hosts.conf of the

That is, the would have vhosts that – rather than having content – each proxy to the “real” servers. Apache can “dNAT” based on the hostname that is used in the request …

Thanks, but none of this helped me. I don’t understand how this works. Where should I write this text in the Apache configuration file?

I have three apache servers setup on an internal network at home. The easiest solution for me was to edit the /etc/hosts host file on the apache server machine as follow: siteone.com sitetwo.com sitethree.com

Then on computer you want to access the site:
Linux computers ( replace x with ip numbers pointing to the IP Address your Apache server is on) /etc/hosts:
192.168.x.x siteone.com
192.168.x.x sitetwo.com
192.168.x.x sitethree.com

Windows computers same thing but hosts file is at C:\Windows\system32\drivers\etc\hosts

That blue thing has address and is the only one visible from inet. Therefore, it should have the Apache that has virtual hosts (which each redirect to “real websites” in

This is a router; it cannot work on port 80 with three servers at once. All traffic from an external IP on port 80 is routed to (example.com), but I need all traffic from (mail.example.com) and (forum.example.com) to go to and then the server (example.com) redirects requests from (forum.example.com) to 192.168 .1.11 and correspondingly (mail.example.com) on

For subdomains to work, should my topology look something like this?

Then that server’s Apache should have three virtual hosts:

Yes, that’s what I want. But how can you redirect traffic in a virtual host not to different folders on the local host, but to another IP address? On server in (/etc/httpd/conf/httpd.conf), I created the virtual host described in the topic above, but it doesn’t work for me. And when I write (forum.example.com) in the browser, nothing happens, the site was not found.

“Virtual Host” might be the wrong terminolgy here.

The original idea of multiple virtual hosts, is where you have a single server with a single IP address, but you want to run 100 (plain http) websites. Each website domain points to the same server DNS name, BUT with a different ServerName directive. The browser sends a “Host Header” for a specific site, and this is checked by apache and routed to the specific web content files.

Early days of SSL this started to break down, you needed multiple IP addresses, but now there’s the concept of SNI, where the virtual host routing can be done from a single IP address (but with a single point of failure).

Is there really no solution to my problem? Once everything is installed on one server, but this is not possible in my situation.

Yes, it has been explained already that you need Apache on to redirect the vhosts using Apache as a reverse proxy. Or nginx as a reverse proxy. Or haproxy to redirect.

What you need to be doing:

Public IP for all domains - example.com mail.example.com and forum.example.com need to go via the router and redirect to as shown in your diagram.

The Apache, Nginx or haproxy then needs to redirect those vhosts to the server IP’s later shown in your diagram.

You will find plenty of examples on the internet with google on how to redirect multiple vhosts. For example using haproxy: How to Map Domain Names to Backend Server Pools With HAProxy you can see how that would fit your situation. If you don’t feel comfortable with haproxy, you can find plenty of examples as well for nginx or Apache.