1

I have the following virtual host file. I have 2 applications that run on port 26876 and 6876. When I add this into my virtual host, it only goes to the 26876 site on both domains. What could be wrong here?

<VirtualHost *:*>
    ServerName xxx.abc.com

        ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:26876/
    ProxyPassReverse / http://127.0.0.1:26876/

</VirtualHost>
<VirtualHost *:*>
    ServerName yyy.abc.com

        ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:6876/
    ProxyPassReverse / http://127.0.0.1:6876/

</VirtualHost>
3
  • 1
    Not sure, but should you include the port number in VirtualHost, like <VirtualHost *:6876> instead of just *:*? May 13, 2021 at 12:00
  • Also if you reverse the order does it always go to 6876 on both domains? May 13, 2021 at 12:17
  • Actually you might just need to configure them on to a single virtual host. Please see serverfault.com/questions/622017/… May 13, 2021 at 12:19

1 Answer 1

1

What could be wrong here?

Unfortunately, it seems likely that some relevant information may be missing from your question.

Using only <VirtualHost *:*> statements, virtual hosts with separate sub-domains should work correctly based on ServerName (e.g. xxx.example.com, yyy.example.com). That is, in isolation, there should be nothing wrong with your virtual host examples above.

Solutions?

As suggested in the comments, you can try specifying a port number in your <VirtualHost> statement e.g.:

<VirtualHost *:80>

    ServerName xxx.abc.com

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:26876/
    ProxyPassReverse / http://127.0.0.1:26876/

</VirtualHost>

<VirtualHost *:80>

    ServerName yyy.abc.com

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:6876/
    ProxyPassReverse / http://127.0.0.1:6876/

</VirtualHost>

This is more common than using any IP/any port (*.*) and can make a difference under some circumstances.

The above assumes that you are trying to connect with HTTP (port 80). HTTPS (port 443) requires additional configuration in general. Don't forget to restart Apache.

Note that editing your original question to include additional details could be helpful, including:

  • What OS you are using.

  • What service(s) you are running on ports 26876 and 6876.

  • The exact steps you are taking when adding the second virtual host.

  • Examples of how you are accessing the services (browser URLs, command line strings, etc.).

  • If reversing the virtual host order makes a difference.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .