# Apache Virtual host

**URL:** <https://forums.rockylinux.org/t/apache-virtual-host/14382>\
**Category:** Rocky Linux Help & Support\
**Created:** [June 2, 2024, 5:19pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382 "2024-06-02T17:19:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 2, 2024, 5:19pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/1 "2024-06-02T17:19:40Z")

</div>

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](http://example.com)  
And  
Third level domain: [forum.example.com](http://forum.example.com)  
Domain website: [example.com](http://example.com) whose IP address is 192.168.1.10  
Domain website: [forum.example.com](http://forum.example.com) IP address is 192.168.1.11  
The main domain is [example.com](http://example.com), how can I set up an Apache virtual host so that when requests come to the [forum.example.com](http://forum.example.com), Apache redirects all traffic to 192.168.1.11? Or is there another solution?

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [June 2, 2024, 5:32pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/2 "2024-06-02T17:32:22Z")

</div>

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 (192.168.1.10 and 192.168.1.11). 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](http://example.com) and [forum.example.com](http://forum.example.com) on the same server, eg: 192.168.1.15 - 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 192.168.1.10, and the forum on 192.168.1.11.

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 2, 2024, 6:03pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/3 "2024-06-02T18:03:47Z")

</div>

Yes, I have done it exactly as you wrote. But what then to do with the external IP address? For example:  
External IP 10.11.12.13 to which the [example.com](http://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 192.168.1.10. External IP and internal IP use port 80.  
The domain [forum.example.com](http://forum.example.com) also points to the external IP address 10.11.12.13, but how can I route requests coming to port 80 to this domain to the internal network to the address 192.168.1.11 My router cannot use two 80 ports on the external IP. I don’t understand how two domains ([example.com](http://example.com) and [forum.example.com](http://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.

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [June 2, 2024, 6:57pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/4 "2024-06-02T18:57:40Z")

</div>

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](http://example.com) and [forum.example.com](http://forum.example.com) - eg: put both on 192.168.1.10

Examples of vhost config: [apache virtual host example - Google Search](https://www.google.com/search?q=apache+virtual+host+example&sca_upv=1&uact=5)

---

<div class="post-metadata">

**Author:** ![stevemowbray](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@stevemowbray](https://forums.rockylinux.org/u/stevemowbray)\
**Post date:** [June 2, 2024, 7:02pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/5 "2024-06-02T19:02:22Z")

</div>

You could use mod\_proxy in Apache to forward requests to the other host.

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 2, 2024, 7:24pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/6 "2024-06-02T19:24:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 2, 2024, 7:26pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/7 "2024-06-02T19:26:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevemowbray](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@stevemowbray](https://forums.rockylinux.org/u/stevemowbray)\
**Post date:** [June 2, 2024, 7:29pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/8 "2024-06-02T19:29:32Z")

</div>

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](https://httpd.apache.org/docs/current/mod/mod_proxy.html)]

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [June 3, 2024, 8:37am UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/9 "2024-06-03T08:37:46Z")

</div>

Would it be something like

```auto
<VirtualHost forum.example.com:80>
  RewriteEngine on
  ProxyPass "http://192.168.1.11/"
  ProxyPassReverse "http://192.168.1.11/"
</VirtualHost>

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

```

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

That is, the 10.11.12.13 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 …

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 7, 2024, 2:44pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/10 "2024-06-07T14:44:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TecWolf](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/tecwolf/32/1193_2.png) [@TecWolf](https://forums.rockylinux.org/u/TecWolf)\
**Post date:** [June 8, 2024, 10:56pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/11 "2024-06-08T22:56:42Z")

</div>

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:  
127.0.0.1 [siteone.com](http://siteone.com)  
127.0.0.1 [sitetwo.com](http://sitetwo.com)  
127.0.0.1 [sitethree.com](http://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](http://siteone.com)  
192.168.x.x [sitetwo.com](http://sitetwo.com)  
192.168.x.x [sitethree.com](http://sitethree.com)

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

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 10, 2024, 10:50am UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/12 "2024-06-10T10:50:25Z")

</div>

![Topology](https://us1.discourse-cdn.com/flex020/uploads/rockylinux/original/2X/5/54095412d7540ef39d6c7fa1f5b5c2459d4a051d.jpeg)

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [June 10, 2024, 11:25am UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/13 "2024-06-10T11:25:54Z")

</div>

That blue thing has address 10.11.12.13 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 192.168.1.0/24).

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 10, 2024, 12:32pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/14 "2024-06-10T12:32:05Z")

</div>

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 192.168.1.10 ([example.com](http://example.com)), but I need all traffic from ([mail.example.com](http://mail.example.com)) and ([forum.example.com](http://forum.example.com)) to go to 192.168.1.10 and then the server 192.168.1.10 ([example.com](http://example.com)) redirects requests from ([forum.example.com](http://forum.example.com)) to 192.168 .1.11 and correspondingly ([mail.example.com](http://mail.example.com)) on 192.168.1.12.

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 10, 2024, 1:15pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/15 "2024-06-10T13:15:57Z")

</div>

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

 ![Topology](https://us1.discourse-cdn.com/flex020/uploads/rockylinux/original/2X/0/0e031fd17930c2375011697496b79b1f441466d4.jpeg)

---

<div class="post-metadata">

**Author:** ![jlehtone](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@jlehtone](https://forums.rockylinux.org/u/jlehtone)\
**Post date:** [June 10, 2024, 1:32pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/16 "2024-06-10T13:32:59Z")

</div>

> [@t-vex](#):
>
> All traffic from an external IP on port 80 is routed to 192.168.1.10

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

- [example.com](http://example.com) in the server
- [mail.example.com](http://mail.example.com) redirected to 192.168.1.12
- [forum.example.com](http://forum.example.com) redirected to 192.168.1.11

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 10, 2024, 1:48pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/17 "2024-06-10T13:48:59Z")

</div>

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 192.168.1.10 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](http://forum.example.com)) in the browser, nothing happens, the site was not found.

---

<div class="post-metadata">

**Author:** ![gerry666uk](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@gerry666uk](https://forums.rockylinux.org/u/gerry666uk)\
**Post date:** [June 10, 2024, 8:02pm UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/18 "2024-06-10T20:02:10Z")

</div>

“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).

---

<div class="post-metadata">

**Author:** ![t-vex](https://avatars.discourse-cdn.com/v4/letter/t/e274bd/32.png) [@t-vex](https://forums.rockylinux.org/u/t-vex)\
**Post date:** [June 11, 2024, 8:28am UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/19 "2024-06-11T08:28:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![iwalker](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.rockylinux.org/iwalker/32/2599_2.png) [@iwalker](https://forums.rockylinux.org/u/iwalker)\
**Post date:** [June 11, 2024, 8:49am UTC](https://forums.rockylinux.org/t/apache-virtual-host/14382/20 "2024-06-11T08:49:12Z")

</div>

Yes, it has been explained already that you need Apache on 192.168.10.2 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](http://example.com) [mail.example.com](http://mail.example.com) and [forum.example.com](http://forum.example.com) need to go via the router and redirect to 192.168.10.2 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](https://www.haproxy.com/blog/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.

[Next page](https://forums.rockylinux.org/t/apache-virtual-host/14382.md?page=2)
