My apologies if this has been asked before. I haven't found an adequate solution so... yeah.

When a specific domain, "example.com" is accessed, I want it to act normally. In other words, it should go to port 80 as expected and interact with Apache.

When a different sub-domain, "mc.example.com" is accessed, I don't want it to access the Apache web server. I want it to go interact with a different program, listening on, say, port 4096. Thus, going to "mc.example.com" would have the same/similar function as "example.com:4096". The service is Minecraft

When a third sub-domain, "vpn.example.com" is accessed, I want it to go interact with a different service, listening on, say, port 687. The service is openVPN

Is there a simple way to do this? If so, what is it? Does it involve configuring a VirtualBox in Apache (a method I tried and failed miserably. xD)? Or can it be done using ipTables? If it means anything, I am running 32-bit Centos 5.5(I believe. Its a recent version of Centos)


It can't be done by anything. When the remote computer opens a TCP connection, all it tells you is the IP address and port number it wants to connect to. It doesn't tell you what hostname it looked up in DNS to get that IP address. (Name-based virtual hosting uses the Host: header that's sent as part of the HTTP protocol, but that's after the connection is open.)

But if you're accessing a different service, the remote computer should be asking to connect to a different port number, and you should be able to route based on that.

If all these programs are speaking HTTP, then you should be able to have your main webserver proxy requests to the appropriate server based on the Host: header.

  • I'll look into this, then. Any advice on how to do this with apache? It would involve using VirtualBoxes, I'm assuming
    – Jarwain
    Feb 17 '12 at 23:27

I know it's an old question, but maybe there is a solution: I've found config of vhost @ work: Try this in virtualhost configuration: ( I'm not 100% sure if this would work! :) )

Can someone confirm it?

<VirtualHost *:80>
    ServerName sub.domain.com
    <Proxy *>
        Order deny,allow
        Allow from all
    ProxyRequests           Off
    ProxyPass               /       http://sub.domain.com:12345/
    ProxyPassReverse        /       http://sub.domain.com:12345/

   #... etc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.