Montag
Aug202007
in
Linux
Linux Ubuntu Administration: Hosting multiple Websites with Apache2
Montag, August 20, 2007 at 1:31PM
With Apache2, it seems to be generally suggested to have one file per site in the sites-available directory of the apache configuration. The main configuration (in apache2.conf) is then including symbolic links to these files:
[php]
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/[^.#]*
[/php]
So what do you do with virtual hosts?
My first try was starting each of the sites files with the following:
[php]
NameVirtualHost *:80
ServerName www.simplificator.com
ServerAdmin info@simplificator.com
ServerAlias simplificator.com
[/php]
This does actually work, but complains in the logs, saying
[php]
[warn] NameVirtualHost *:80 has no VirtualHosts
[warn] NameVirtualHost *:80 has no VirtualHosts
[/php]
for the second and third domain. What's going on?
Most people on the web say stuff like 'change the *:80 to a _default_:80' or similar - focusing on tricking apache to believe it actually has several different ip addresses an no conflicts. Trial and error until it works! Sometimes this breaks connections from localhost (which is cruical for restful services and the like, so that's no minor issue). The apache documentation was too cryptic for me to help in any practical way. Seems one needs to understand the concept before you can understand the explanation of the concept.
It took me a while to figure it out. There should be one NameVirtualHost *:80 only (and maybe one for port 443 if you use https). Since people normally don't touch apache2.conf but each site file, they normally copy the header of these files and end up with multiple NameVirtualHost directives.
The solution:
Use the /etc/apache2/conf.d directory and put a file in there called NameVirtualHost, for example. Put the following in there: [php]
NameVirtualHost *:80
NameVirtualHost *:443
[/php]
remove all the NameVirtualHost directives from your site configs in sites-available and use something like this:
[php]
ServerName www.simplificator.com
ServerAdmin info@simplificator.com
ServerAlias simplificator.com
...
[/php]
The conf.d-file will be read exactly once. I guess everyone who has a running server which doesn't complain at reboot has this, so it's no magic at all. But you won't easily read about it.
I put this here because I had such a hard time figuring it out. Hope someone else has an easier time.
[php]
# Include the virtual host configurations:
Include /etc/apache2/sites-enabled/[^.#]*
[/php]
So what do you do with virtual hosts?
My first try was starting each of the sites files with the following:
[php]
NameVirtualHost *:80
ServerName www.simplificator.com
ServerAdmin info@simplificator.com
ServerAlias simplificator.com
[/php]
This does actually work, but complains in the logs, saying
[php]
[warn] NameVirtualHost *:80 has no VirtualHosts
[warn] NameVirtualHost *:80 has no VirtualHosts
[/php]
for the second and third domain. What's going on?
Most people on the web say stuff like 'change the *:80 to a _default_:80' or similar - focusing on tricking apache to believe it actually has several different ip addresses an no conflicts. Trial and error until it works! Sometimes this breaks connections from localhost (which is cruical for restful services and the like, so that's no minor issue). The apache documentation was too cryptic for me to help in any practical way. Seems one needs to understand the concept before you can understand the explanation of the concept.
It took me a while to figure it out. There should be one NameVirtualHost *:80 only (and maybe one for port 443 if you use https). Since people normally don't touch apache2.conf but each site file, they normally copy the header of these files and end up with multiple NameVirtualHost directives.
The solution:
Use the /etc/apache2/conf.d directory and put a file in there called NameVirtualHost, for example. Put the following in there: [php]
NameVirtualHost *:80
NameVirtualHost *:443
[/php]
remove all the NameVirtualHost directives from your site configs in sites-available and use something like this:
[php]
ServerName www.simplificator.com
ServerAdmin info@simplificator.com
ServerAlias simplificator.com
...
[/php]
The conf.d-file will be read exactly once. I guess everyone who has a running server which doesn't complain at reboot has this, so it's no magic at all. But you won't easily read about it.
I put this here because I had such a hard time figuring it out. Hope someone else has an easier time.


Reader Comments