Why does Apache say “file does not exist” with this directory alias

apache-http-serverwebserver

I am setting up a small web server. I am having trouble with Apache not being able to find the alias. My DocumentRoot is /var/www/htdocs but I have some files on a different (bigger) partition under /home/user/Documents/a_directory/CurrentCaptures that I want to be able to view on the website.

My /var/www/conf/httpd.conf has 2 aliases as follows:

Alias /icons/ "/var/www/icons/"

<Directory "/var/www/icons/">
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

# Added by me
Alias /CurrentCaptures "/home/user/Documents/a_directory/CurrentCaptures"

<Directory "/home/user/Documents/a_directory/CurrentCaptures">
    Options Indexes
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

I left the /icons/ alias in there to test it, and if I go to http://localhost/icons/ in a browser, it works. But when I try to go http://localhost/CurrentCaptures/ I get a 404 Not Found error.

In /var/www/logs/error_log I get this error:

[Mon Aug 4 11:02:30 2014] [error] [client 192.168.10.100] File does not exist: /home/user/Documents/a_directory/CurrentCaptures/

Any ideas?

Best Answer

The Apache process most likely doesn't have permission to descend into /home/user.

Apache normally runs as an unprivileged user (commonly named "http", "httpd" or "www-data", but variations exist). That user does not have permission to descend into another user's home directory.

If you aren't concerned about security, the easiest way to work around this is to add world execute permission on the directories (something like mode 0711), and world read permission (0644) on the files you want to make available to the web server. On a directory, "execute" means descend into, and "read" means list the files in the directory. So by giving execute permission, you allow the web server to read known files (subject to the permissions on the file), but not enumerate the contents of the directory.

A more "correct" solution would be to move the files into a directory hierarchy that is not user-specific. You could do that for example by either moving the files to some other location (outside of a particular user's home directory), or by using bind mounts. File permissions would still be in effect, so the files would need to be readable to the web server, but you wouldn't need to grant the web server any access to your home directory.

Related Question