Below is my config file:
NameVirtualHost 12.34.56.78:80
<VirtualHost 12.34.56.78:80>
ServerAdmin admin@domain1.com
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /srv/www/domain1.com/public_html1/
ErrorLog /srv/www/domain1.com/logs/error.log
CustomLog /srv/www/domain1.com/logs/access.log combined
</VirtualHost>
<VirtualHost 12.34.56.78:80>
ServerAdmin admin@domain2.com
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /srv/www/domain2.com/public_html1/
ErrorLog /srv/www/domain2.com/logs/error.log
CustomLog /srv/www/domai开发者_高级运维n2.com/logs/access.log combined
</VirtualHost>
The thing is when I put www.domain1.com
into browser, apache2 doesn't retrieve the web page resides in /srv/www/domain1.com/public_html1/
, instead, it gets the page from the default document root defined in another file. However, if I put www.domain2.com
, everything works fine. I don't see any difference between two VirtualHost config block, so I wonder what does make the difference. BTW, I haven't put any .htaccess
file under their document root.
Try checking your Apache config by issuing:
/usr/sbin/apache2ctl -S
I guess your "default" virtual host uses "www.domain1.com" as its ServerName, thus it responds to the request to "www.domain1.com".
On my machine this happened due to "www.domain1.com" being my machine's hostname. If ServerName is not specified, Apache tries to guess - causing the abovementioned problem.
I solved this by specifying "ServerName default" in sites-available/default.
This might be of some help as well:
http://httpd.apache.org/docs/current/dns-caveats.html
If you are on Windows and probably using a ZendSever, than you MUST do next:
Open file "hosts" in directory "C:\Windows\System32\drivers\etc"
Add
127.0.0.1 www.domain1.com
under
127.0.0.1 localhost
127.0.0.1 domain1.com
It should look like this:
127.0.0.1 localhost
127.0.0.1 domain1.com
127.0.0.1 www.domain1.com
127.0.0.1 domain2.com
127.0.0.1 www.domain2.com
127.0.0.1 domain3.com
127.0.0.1 www.domain3.com
All domains need to be registered in this file.
Just wanted to say that this caught me out too, and changing the ServerName in the default apache site worked for me, as did simply disabling that site using
a2dissite default
Then reloading apache.
精彩评论