Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a remote server with IP address 10.72.254.248, I want to set up multiple virtual hosts on this server by giving different ports for each virtual host.

my httpd.conf:

Listen 80
Listen 3333

NameVirtualHost *:80
NameVirtualHost *:3333

<VirtualHost *:80> 
     DocumentRoot "/path/to/site1/" 
     ServerName *:80
</VirtualHost>

<VirtualHost *:3333> 
     DocumentRoot "/path/to/site2/" 
     ServerName *:3333
</VirtualHost>

If no port specified, it will hit site1 (port 80) When I go to 10.72.254.248 or 10.72.254.248:80 it opens site1 successfully

But when I try 10.72.254.248:3333 it doesn't work.

Is the issue to do with the syntax? or maybe with /etc/hosts file? or firewall?

Please help

EDIT:

When I try to connect to 10.72.254.248:3333, I get the following error message:

Can't connect to server 10.72.254.248:3333

share|improve this question
2  
'doesn't work' - hangs, gives an error, gets a page but 404, permission denied? What kind of 'doesn't work'. –  EightBitTony Jun 22 '11 at 14:04
3  
(1) Don't use non-standard ports unless you have a good reason (You have not provided a good reason in your question, therefore you should not be using a non-standard port. Expect strict firewalls to stomp on random high-numbered ports.). (2) See what EightBitTony said above :) –  voretaq7 Jun 22 '11 at 14:14

2 Answers 2

up vote 3 down vote accepted

Check netstat -an and make sure Apache is listening on port 3333. Check nothing else is listening instead. If it is, it's most likely a firewall issue (iptables -L and look for a rule allowing port 3333).

share|improve this answer
    
I've edited the question, it gives me an error "Can't connect to server 10.72.254.248:3333". When I tried stopping iptables firewall service "service iptables stop", it worked! Now, of course, I don't want to stop the firewall, I only want to allow that specific 3333 port, how can I do that, please? –  evilReiko Jun 23 '11 at 10:26
1  
the answer to that is both simple, and complex - simple, you need to add a rule allowing traffic on port 3333. Complex - how you add that rule depends entirely on what you use to build your current set of firewall rules. It's probably a single iptables command, but integrating it into your firewall requires knowing what firewall you use (its iptables based, but what product manages it for you, if anything). –  EightBitTony Jun 23 '11 at 10:42

At first: "It doesn't work" is no propper error description. What do you expect to see? What do you actually observe?

Having said that, it seems you are mixing up the concepts of name based virtual hosting and IP/Port based virtual hosting. In the first case (where you actually need the NameVirtualHost and ServerName directive, you can have multiple virtual hosts on the same IP/port. Apache decides which one to use by comparing the contents of the Host header sent with each request by the client with value of the ServerName of the virtual host.

In your case, where you have a single vhost on a port, this is not necessary. Thus, you should remove the NameVirtualHost directives and the ServerName directives (which are in the wrong format nevertheless).

Read http://httpd.apache.org/docs/2.2/vhosts/name-based.html for more information about the concept of name-based virtual hosting.

share|improve this answer
    
As you said, seems like I mixed between Name-base and IP-base, thanks for the info –  evilReiko Jun 23 '11 at 11:38

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.