Basj
Basj

Reputation: 46229

Is Directory relative to local server path or public URL path?

I understand that DocumentRoot refers to server's local path (on disk), i.e. with

<VirtualHost :80>
ServerName example.com
DocumentRoot /home/www/mysite1/

browsing http://example.com/foo/index.html will access /home/www/mysite1/foo/index.html on the server.

Then, should I use (that sometimes seems to work):

<Directory "/">
Require all granted
</Directory>

(isn't it strange to reference to /, i.e. root of server's filesystem?)

or should I copy/paste the DocumentRoot into Directory like this:

DocumentRoot /home/www/mysite1/
<Directory "/home/www/mysite1/">
Require all granted
</Directory>

?

If so, this is annoying to have to copy/paste into Directory each time we modify the DocumentRoot, why is this duplication of configuration path needed? Isn't there a way to say Require all granted for everything without having to duplicate the path?

Upvotes: 0

Views: 1288

Answers (2)

Quentin
Quentin

Reputation: 944036

See Configuration Sections in the Apache manual.

<Directory> does, indeed, refer to the file system path.

You can specify rules for an entire website, independent of locations on the filesystem, with <Location>.

Upvotes: 1

Mykhailo YATSYSHYN
Mykhailo YATSYSHYN

Reputation: 179

I used this setting

<VirtualHost *:80>
    ServerName seminarium.loc
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/seminarium.loc/public

    <Directory /var/www/seminarium.loc/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    </Directory>

   ErrorLog /var/www/seminarium.loc/error.log
   CustomLog /var/www/seminarium.loc/access.log combined
</VirtualHost>

The path in the directory specifies the directory to which the options will be applied. It is natural to exclude possible conflicts, it is desirable to specify the path to the DocumentRoot as if there are several sites with "/" they will overwrite options to each other

Upvotes: 0

Related Questions