1

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>
6
  • What sort of errors are you getting?
    – NickW
    Aug 14, 2013 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. Aug 14, 2013 at 13:33
  • @fboaventura, Opps, I made a typo in my question. I have corrected it. My config file doesn't have that typo. Aug 14, 2013 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". Aug 14, 2013 at 15:42
  • @WuYongzheng what errors are you getting? I've made this same configuration at my machine and it just worked. Aug 16, 2013 at 16:43

2 Answers 2

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>
1

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

2
  • Does that mean I need to duplicate the <VirtualHost>...</VirtualHost> three times for both a.foo.com and b.foo.com? Aug 14, 2013 at 15:45
  • Yes, you will need different configuration options for the https enabled hosts..
    – NickW
    Aug 14, 2013 at 15:58

You must log in to answer this question.

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