linux - Apache 2.4 vhost not working
2014-07
We have a new Centos server installed with Apache 2.4.9. I'm trying to get the vhost working. DNS resolves to the right machine, and I can see the default Apache page, so it's not a firewall issue and Apache runs.
/etc/httpd/conf/httpd.conf
Include conf.d/*.conf
/etc/httpd/conf.d/vhosts.conf
<VirtualHost *>
ServerName www.abctest.com
DocumentRoot /websites/abctest.com/htdocs
<Directory /websites/abctest.com/htdocs/public>
AllowOverride All
</Directory>
</VirtualHost>
ls /etc/httpd/modules
modules/mod_vhost_alias.so
website
In /websites/abctest.com/htdocs is an index.php file with helloworld in it. After restarting httpd, I still get the Apache page, not the helloworld text.
How can I get this working?
Couple of items to check:
Make sure you do not have other VirtualHost entries that may be getting called afterwards.
Typically the * entry in VirtualHosts is used for requests without a ServerName, so although I would have expected that to work, try changing the first line from: to (Assuming you are using the default port 80 for the host).
Those random items aside, take a look at your access_log and error_log. They may help you identify what path is being utilized to then locate within your .conf file to help narrow down the conflict/cause.
You need to enable name-based virtual hosting.
On my Centos box it's towards the bottom of /etc/httpd/conf/httpd.conf
as
# NameVirtualHost *:80
You need to remove the '#' symbol from the start of the line to enable it and then restart Apache.
Without the above, Apache is using IP based virtual host. As (I presume) the name of your host and of the virtual host resolve to the same IP address then the first one matched wins, which in your case is the Apache start page.
After upgrading to Lion 10.7.2 today, Apache virtual hosts are not working anymore. When I go to http://XYZ.localhost
, it say "server not found".
I am using Apache on my Mac OS X Lion and until today, it was working fine. I can access http://localhost
but I can't access http://XYZ.localhost
My /etc/hosts
file is like below;
127.0.0.1 XYZ.localhost
My /etc/apache2/extra/httpd-vhosts.conf
file is like below;
<VirtualHost *:80>
ServerName XYZ.localhost
DocumentRoot /Library/WebServer/Documents/XYZ
<Directory /Library/WebServer/Documents/XYZ>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I think I once had this problem too, after another OS X update, but I can't remember how I solved it.
Is it a user permission issue? Or is there something wrong with Apache or any other setting?
EDIT: It seems like my /etc/hosts
file is not working correctly. Even if I add something like 127.0.0.1 apple.com
it still goes to the real apple.com. Maybe this might help to solve the problem.
You need this in your conf:
NameVirtualHost *:80
So it should look like:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName XYZ.local
DocumentRoot /Library/WebServer/Documents/XYZ
<Directory /Library/WebServer/Documents/XYZ>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You may also need to edit your main httpd.conf to include the httpd-vhosts.conf