Web root Alias directory
Quoted from http://httpd.apache.org/docs/2.2/urlmapping.html
Files Outside the DocumentRoot
There are frequently circumstances where it is necessary to allow web access to parts of the filesystem that are not strictly underneath the DocumentRoot. Apache offers several different ways to accomplish this. On Unix systems, symbolic links can bring other parts of the filesystem under the DocumentRoot. For security reasons, Apache will follow symbolic links only if the Options setting for the relevant directory includes FollowSymLinks or SymLinksIfOwnerMatch.
Alternatively, the Alias directive will map any part of the filesystem into the web space. For example, with
Alias /docs /var/web the URL http://www.example.com/docs/dir/file.html will be served from /var/web/dir/file.html.....
What does this mean?
sudo gedit /etc/apache2/sites-available/default
It will open:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Now add the alias and the directory permissions , suppose add /pics and I will use the Pictures directory in my home to server it.
output would be like:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
Alias /docs /home/user/Pictures
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
<Directory /home/user/Pictures>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Now restart apache service
sudo service apache2 restart
Now when typing localhost/pics
this will serve from /home/user/Pictures
instead of /var/www
Related videos on Youtube
Chumpen Suksapar
Updated on September 18, 2022Comments
-
Chumpen Suksapar over 1 year
I want to use another directory come to use in my web server with Apache in Ubuntu?
I'm new user in Ubuntu. I want step by step for understand. Help me please.
ps. KUbuntu 14.10, apache2
-
Chumpen Suksapar almost 9 yearsi have only '000-default.conf' in /etc/apache2/sites-available.
-
Chumpen Suksapar almost 9 yearsin side this file no have <Directory> tage