Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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". If it helps, 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. If it helps, 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)

Thanks for your help.

share|improve this question
    
When the domains are accessed by what? As cjm's answer explains, what you ask can't be done at the TCP/IP level. There may be a way to do it in your application. –  Gilles Feb 18 '12 at 23:17
add comment

1 Answer

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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