Solving “403 Forbidden” for NGINX

There are several cases you can face “403 Forbidden” when working with NGINX.

1/ Incorrect Index File

One of the most common causes of the “403 Forbidden” error is not having a correctly set up index file.

The NGINX configuration file specifies which index files to load, and in which order. For example, this line tells NGINX to look for index.html:

index index.html;

2/ File Permissions

Incorrect file permissions are another cause of the “403 Forbidden” error. The standard setting of 755 for directories and 644 for files is recommended for use with NGINX.

Set the permissions of each directory at this location to 755 with the command:

sudo chmod 755 [directory name]

For example, to set the permissions of the /srv/www directory, the command is:

sudo chmod 755 /srv/www

Then go to the web document root directory:

cd /srv/www

Change the permissions of all the files in this directory with the command:

sudo chmod 644 *

3/ httpd Permission

httpd is one of the system processed which are under targetted SELinux policy. We need to set context type httpd_sys_content_t for the web folder in order to allow httpd to access it

chcon -R -t httpd_sys_content_t /srv/www