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

I have a server with one IP address. I want to run several virtual hosts in an Apache 2.2. And I want all virtual hosts to be accessible on port 80 (plain http), 8000 (plain http) and 443 (ssl).

For example, I have two virtual hosts a.foo.com and b.foo.com. I want the following url to be accessible: http://a.foo.com, http://a.foo.com:8000, https://a.foo.com, http://b.foo.com, http://b.foo.com:8000 and https://b.foo.com. The virtual host a.foo.com should have the same content on all ports.

Here is my failed attempt. I haven't come to the SSL yet. I can't even figure out just the two plain http ports.

Listen 80
Listen 8000
NameVirtualHost *

<VirtualHost *>
ServerName a.foo.com
DocumentRoot /www/a
</VirtualHost>

<VirtualHost *>
ServerName b.foo.com
DocumentRoot /www/b
</VirtualHost>
share|improve this question
    
What sort of errors are you getting? –  NickW Aug 14 '13 at 11:19
    
As far as I can see, you are just missing the ServerName b.foo.com to make things a little different. But, as NickW stated, knowing the errors are the best way to find the solution. –  fboaventura Aug 14 '13 at 13:33
    
@fboaventura, Opps, I made a typo in my question. I have corrected it. My config file doesn't have that typo. –  Wu Yongzheng Aug 14 '13 at 15:33
    
@NickW, I should have mentioned it. Good you asked. The error is "You're speaking plain HTTP to an SSL-enabled server port". –  Wu Yongzheng Aug 14 '13 at 15:42
    
@WuYongzheng what errors are you getting? I've made this same configuration at my machine and it just worked. –  fboaventura Aug 16 '13 at 16:43

2 Answers 2

It should be something like the following

Listen *:80
Listen *:8080

NameVirtualHost *:80
NameVirtualHost *:8080

<VirtualHost *:80>
   ServerName a.foo.com
   DocumentRoot /www/a
</VirtualHost>

<VirtualHost *:8080>
   ServerName a.foo.com
   DocumentRoot /www/a
</VirtualHost>
share|improve this answer

For each virtual host you need to include the port also, say "VirtualHost 172.20.30.40:8080"

please refer http://httpd.apache.org/docs/2.2/vhosts/examples.html

share|improve this answer
    
Does that mean I need to duplicate the <VirtualHost>...</VirtualHost> three times for both a.foo.com and b.foo.com? –  Wu Yongzheng Aug 14 '13 at 15:45
    
Yes, you will need different configuration options for the https enabled hosts.. –  NickW Aug 14 '13 at 15:58

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.