2

I have a Centos webserver set up with 2 websites. Initially it only had one website and virtualhost config was added to the end of the httpd.conf file. Not best practice I know however it worked fine and looks as follows.

<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
#ServerAdmin [email protected]
DocumentRoot /var/www/html/example/
ErrorLog /var/log/httpd/example_error.log
CustomLog /var/log/httpd/example_access.log combined
#loglevel warn
<Directory />
    #Options Indexes FollowSymLinks
    #AllowOverride None
    #Require all granted
    Options Indexes FollowSymLinks MultiViews
    Allowoverride All
    Order allow,deny
    allow from all
</Directory>

A second development website was added which was a copy of the first one and the virtual host was created just below the first one in the httpd.conf file as follows:

<VirtualHost *:80>
ServerName dev.example.com
ServerAlias dev.example.com
DocumentRoot /var/www/dev.example.com/html
#ErrorLog /var/log/httpd/dev.example.com/error.log
#CustomLog /var/log/httpd/dev.example.com/requests.log combined
<Directory />
    #Options Indexes FollowSymLinks
    #AllowOverride None
    #Require all granted
    Options Indexes FollowSymLinks MultiViews
    Allowoverride All
    Order allow,deny
    allow from all
</Directory>

The second virtual host config is definitely being read as it displays the dev website but the directory directives seem to be ignored.

I have also tried making the second directory path explicit i.e.

 <Directory /var/www/dev.example.com/html>

However it was ignored again.

Am I missing something in the set up of the second site that will allow the directory directive to be read?

2
  • "Directory /" is the / if your filesystem, don't use it in virtualhost. Thats always to be denied! You are also setting allowoverride all, set it to none, otherwise .htaccess files may be overriding the behaviour you expect. Aug 28, 2017 at 11:04
  • Hi Ezra, thanks for the info. Making the directory paths explicit helped however I tested changing the allowoverride all to none for the website that was working and it broke the website so for me the setting needs to be allowoverride all. I'm going to put all my steps in a response below.
    – jmck
    Aug 29, 2017 at 10:11

3 Answers 3

2

Directory / refers to the root directory of the server. Try Location / to refer to the URL specific to the virtualhost.

1
  • Hi ptman, thanks and making it specific was part of what I needed to do. I'm going to put all my steps in an answer below.
    – jmck
    Aug 29, 2017 at 10:13
0

Thanks to both above for their information. It threw me that one site was working and one wasn't when the config file wasn't set up right. I would have assumed both sites wouldn't work.

  1. Remove the directory directive from the virtualhost section.
  2. Make the directory paths explicit i.e.

    <Directory /var/www/dev.website1.com/html>

  3. Leave allowoverride all in place.

  4. Restart the service.

Additionally while one website was working and the other wasn't it until both website directory directives were set with an explicit path that it started to work.

0

you can use this code

<VirtualHost *:80>
        ServerName gandom.local
        ServerAlias www.gandom.local
        DocumentRoot /var/www/html/gandom
        <Directory /var/www/html/gandom>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>

You must log in to answer this question.

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