0

I have an Ubuntu 14.04 server at http://images.example.com with this in /etc/apache2/sites-enabled/richblockspoorblocks.com.conf:

<VirtualHost *:80>
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias images.example.com
        Header set Access-Control-Allow-Origin "*"
        DocumentRoot /home/username/var/www/example.com/public_html
        ErrorLog /home/username/var/www/example.com/logs/error.log
        CustomLog /home/username/var/www/example.com/logs/access.log combined
</VirtualHost>

I have a file /home/username/var/www/example.com/public_html/test.txt.

But when I navigate my browser to http://images.example.com/test.txt, I get a 403 forbidden error.

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

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

Here's what I see when I run ls -la while in ~/:

drwxrwxr-x 3 www-data username 4096 May 20 21:32 var

error.log only has a client denied by server configuration message.

I've already run apache2 restart.

What must I change to see test.txt in my browser?

Username
  • 173
  • 1
  • 5
  • 13

1 Answers1

1

You seem to be placing your website files and DocumentRoot in a /home/user sub-directory:

    DocumentRoot /home/username/var/www/example.com/public_html

Usually, Apache works in /var/www, you might have a mistake nesting like that in your user's home directory. If you upload and point the DocumentRoot somewhere else than the default location (/var/www/), you might need to fix the owner/group/others and their permissions, so the user or group (www-data) for apache can read them.

Is there any reason to be using your user's home for the webserver DocumentRoot?

If you really want it there, you might try to change the group, to allow apache to read it:

I don't recommend this, unless you know what you are doing

chgrp -R www-data /home/username/var/www/example.com/public_html

That should probably make it work. Although you might also have to change some permissions, depending how you copied/uploaded the files to that directory.

ps. Again, unless there is some really good reason for that directory structure, I would go for the default /var/www.

Leo Gallego
  • 1,893
  • 9
  • 17
  • I put everything in `/home/user` because the partition it's mounted on has a lot of inodes, which I need. Also, I'll update my question with ownership info. I haven't run any code you've recommended yet. – Username May 22 '18 at 05:31
  • I ran `chgrp -R www-data /home/username/var/www/example.com/public_html` and `apache restart`. But I still get the 403 error trying to open the file in my browser. – Username May 22 '18 at 15:42
  • I ended up moving everything to `/var/www` after reinstalling the Ubuntu setup on one partition. Lots of Inodes – Username May 22 '18 at 18:55