2

I've got Apache set up on a remote server.

Here's the contents of file /etc/apache2/sites-available/example.com.conf:

<VirtualHost *:80>
     ServerAdmin admin@example.com
     ServerName example.com
     ServerAlias images.example.com
     DocumentRoot /home/myUserName/var/www/example.com/public_html/
     ErrorLog /home/myUserName/var/www/example.com/logs/error.log
     CustomLog /home/myUserName/var/www/example.com/logs/access.log combined
</VirtualHost>

I've set up the right "A" and "AAAA" records with my hosting provider. But when I go to http://images.example.com, I get a 403 error.

Forbidden
You don't have permission to access / on this server.

Apache/2.4.7 (Ubuntu) Server at images.example.com Port 80

How do I set things up so that going to http://images.example.com lets me see the contents of /home/myUserName/var/www/example.com/public_html/?

Update

Contents of error.log:

[Sun May 20 21:37:05.305775 2018] [authz_core:error] [pid 4858] [client 2601:587:5:6a70:428d:5cff:fe71:b1e4:56518] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:41:15.517163 2018] [authz_core:error] [pid 4859] [client 51.38.12.23:42405] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:43:49.090780 2018] [authz_core:error] [pid 4860] [client 2601:587:5:6a70:428d:5cff:fe71:b1e4:56678] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:48:59.756624 2018] [authz_core:error] [pid 4861] [client 179.127.179.39:43803] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/
[Sun May 20 21:53:22.709395 2018] [authz_core:error] [pid 4864] [client 178.73.215.171:28502] AH01630: client denied by server configuration: /home/myUserName/var/www/example.com/public_html/

Running ls -la /home/myUserName/var/www/example.com/public_html/ outputs this:

total 12
drwxrwxr-x  3 myUserName myUserName 4096 May 20 22:58 .
drwxrwxr-x  4 myUserName myUserName 4096 May 20 21:32 ..
drwxr-xr-x 13 myUserName myUserName 4096 Apr 14 02:18 tile
Username
  • 173
  • 1
  • 5
  • 13
  • 1
    Check your error log. Then check your permissions. – Michael Hampton May 20 '18 at 20:28
  • @MichaelHampton Updated question – Username May 20 '18 at 20:31
  • @kubanczyk Running `chown www-data var -R` and then restarting Apache service still gives the 403 error – Username May 20 '18 at 21:23
  • 1
    As was stated in the accepted answer to the duplicate question, you need to make sure that the `www-data` user has execute permissions for each directory in the entire path. Changing the permissions of part of the chain, starting at `/home/myUsername/var` is not sufficient. – Jenny D May 30 '18 at 07:31

2 Answers2

1

First verify that basic access to files works, by putting a file in that directory and accessing it directly via the proper URL. Requesting a directory/ path either opens the corresponding DirectoryIndex file, or gives a 403 if there isn't any, which adds to the confusion.

Regarding your question. If I understood right that opening / should display the contents of that directory, this can be achieved by either writing a custom listing script in php and such, or by just letting Apache mod_autoindex do it by enabling Options +Indexes and tweaking its settings.

theultramage
  • 413
  • 1
  • 5
  • 15
0

There should be a directory and options to allow access, and 403 error I think that in the directory home there is no file like index.html, index.php also it could mean that you didn't set "Require all granted" option. Example:

<VirtualHost *:80>
  ServerAdmin admin@example.com
     ServerName example.com
     ServerAlias images.example.com
     DocumentRoot "/home/myUserName/var/www/example.com/public_html/"
     ErrorLog /home/myUserName/var/www/example.com/logs/error.log
     CustomLog /home/myUserName/var/www/example.com/logs/access.log combined
    <Directory "/home/myUserName/var/www/example.com/public_html">
      Options -Indexes +FollowSymLinks
      DirectoryIndex index.html index.php 
      Require all granted
    </Directory>
<VirtualHost *:80>

To see the contents of the the directory change -Indexes to +Indexes

Talal Al-Khalifa
  • 668
  • 5
  • 12