Out of the box 403 error on virtual server

Posted January 31, 2020 234 views

Out of the box I am getting a 403 Forbidden error on a new virtual host.

I am using as simple of a server block as possible

server {
        listen 80;
        listen [::]:80;


        root /var/www/carttest1/public;
        index index.html;

        location / {
                try_files $uri $uri/ =404;

The permissions for /var/www/carttest1/public are:

drwxrwxr-x  4 tyson www-data   4096 Jan 30 23:22 public

Same with the permissions of the files within it.

drwxrwxr-x  4 tyson www-data 4096 Jan 30 23:22 .
drwxrwxr-x 14 tyson www-data 4096 Jan 30 23:44 ..
-rw-rw-r--  1 tyson www-data  593 Jan 30 23:22 .htaccess
drwxrwxr-x  2 tyson www-data 4096 Jan 30 23:22 css
-rw-rw-r--  1 tyson www-data    0 Jan 30 23:22 favicon.ico
-rw-rw-r--  1 tyson www-data 1823 Jan 30 23:22 index.php
drwxrwxr-x  2 tyson www-data 4096 Jan 30 23:22 js
-rw-rw-r--  1 tyson www-data   71 Jan 30 23:22 mix-manifest.json
-rw-rw-r--  1 tyson www-data   24 Jan 30 23:22 robots.txt
-rw-rw-r--  1 tyson www-data 1194 Jan 30 23:22 web.config

I have tried setting the owner to www-data as well to no effect.

And in sudo tail -f /var/log/nginx/error.log I constantly get

*1 directory index of "/var/www/carttest1/public/" is forbidden, client:, server:, request: "GET / HTTP/1.1", host: ""

Am I missing a flag somewhere?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


The problem is that in your Virtual Host you have set only index.html as an index but in your public folder, you only have index.php so Apache is failing to find a directory index.

To fix that either add index.php to your index list like this:

        index index.php index.html;

Or change the index.html to index.php:

        index index.php;

After that run a config test:

sudo apache2ctl -t

And if you get Syntax OK, then restart Apache and it should work as expected:

systemctl restart apache2