0

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?

2
  • 1
    This is an old question, but the first thing you should do in a case like this is to check the output of apachectl -S which will dump your web server configuration in a quite readable format. Make sure that the vhost is listed, and if not, check to see why it isn't. The vhost will never work if it isn't included in that output.
    – user
    May 28, 2016 at 13:57
  • Beware that in some systems (e.g. Ubuntu), if the system hostname is assigned an FQDN, the default Apache VirtualHost could always take precedence to serve that FQDN, even if you define your own VirtualHost with the host FQDN as the ServerName. Apr 9, 2019 at 1:51

4 Answers 4

0

Try putting a specific ip and port in each of your VirtualHost blocks. So put:

<VirtualHost 127.0.0.1:80>
0

Your VirtualHost configuration indicates that apache accepts request from any of the interfaces in the host but it should have a Host: www.abctest.com header to select DocumentRoot as /websites/abctest.com/htdocs. Generally any other Host header will cause apache to use the default VirtualHost to be used.

In case if you are trying to open the webpage with http://localhost then you would end up getting pages from default DocumentRoot.

You can check this out more easily with curl command.

curl -L 'http://www.abctest.com'

And also make sure that you have a IP to host mapping for www.abctest.com in /etc/hosts file some thing as below.

127.0.0.1   www.abctest.com www
1
  • I was able to see it using curl. Ended up changing .dev to .test
    – M at
    Oct 29, 2021 at 7:41
0

A 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:

<VirtualHost *>

to

<VirtualHost www.abctest.com:80>

(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.

-1

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.

2
  • I don't see that line in any of the config files inside /etc/httpd. In the Apache 2.4 upgrade page it says that The NameVirtualHost directive no longer has any effect, other than to emit a warning. Any address/port combination appearing in multiple virtual hosts is implicitly treated as a name-based virtual host. See httpd.apache.org/docs/2.4/upgrading.html
    – SPRBRN
    Jun 13, 2014 at 12:34
  • Oops! I homed in on the CentOS bit instead of Apache 2.4! My CentOS runs Apache 2.2. I've just looked at my Fedora 20, which runs Apache 2.4 and I've a similar <VirtualHost> entry to yours with the exception that I've added it to the end of the main httpd.conf file (oh! and it also differs in that it works :-p). Maybe worth trying it there just to see if it makes a difference? Jun 13, 2014 at 20:51

You must log in to answer this question.

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