How to Solve 403 forbidden NGINX

Spread the love
  • 1

How to Solve 403 forbidden NGINX

The browser error of “403 Forbidden”  is the most well-known mistake experienced when working with NGINX. In this article we are going to discuss what is the causes of NGINX error, how to locate the issue and how to solve 403 forbidden NGINX.
Causes of 403 forbidden NGINX

About the Error

“403 Forbidden” is a universally handy NGINX error which demonstrates that you have requested something that NGINX – for an assortment of potential reasons – can’t deliver. “403” is really a HTTP status code that implies that the web server has received and understood the command, however that it can’t make any further move.


Finding the NGINX Configuration File

Originally the NGINX design documents are situated in/etc/nginx. In the event that you check this index, you will locate number of configuration files for NGINX’s different modules.

The main configuration file of NGINX is /etc/nginx/nginx.conf.This is the document with the greater part of the principle orders for NGINX, like Apache’s fundamental httpd.conf file.

To edit this file, use the command:

  • CentOS 7sudo nano /etc/nginx/conf.d/
  • Ubuntu 16.04 sudo nano /etc/nginx/sites-available/

Incorrect index file – Causes of 403 forbidden NGINX

The most common causes of error is incorrect setup index file

The NGINX design record indicates which list documents to stack, and in which arrange. For instance, this line advises NGINX to search for index.html, then index.htm, then index.php:

index index.html index.htm index.php;

If you cannot find all these 3 files, NGINX restores a “403 Forbidden” error.

READ  Custom Web Design vs Website Template - [Infographic]

Note: These files name are case sensitive. If index.html [“i” should in small letter], but the record is named Index.html, this will cause a “403 Forbidden” error.

If this error happen to you, you can edit NGINX file as discussed above and add file name to the index configuration line.

For instance, to add to the rundown of perceived file documents, alter this line to peruse:

index index.html index.htm index.php;

Save and Exit the file, at that point restart NGINX with the command as below.

sudo nginx -s reload

Autoindex – Causes of 403 forbidden NGINX

Alternative solution is the turn on the NGINX directory index. This is because, for some security reason by default NGINX directory is turn off.

If you want to demonstrate the registry file in circumstances where NGINX can’t discover (or recognize) a record document, you can edit the NGINX files as discussed above and add 2 lines of codes as below:

autoindex on;

autoindex_exact_size off;

These designs must be added to a location block. You can either add them to the location / block,  or include another one. The last outcome will resemble:

location / {
  [pre-existing configurations, if applicable]
  autoindex on;
  autoindex_exact_size off;

You can also activate the directory indexing on in a specific directory, if you do not want it to be available site-wide:

location /myfiles {
  autoindex on;
  autoindex_exact_size off;

Save and exit the file, then restart NGINX with the command:

sudo nginx -s reload


File Permissions – Causes of 403 forbidden NGINX

Another cause might be incorrect setting of file permission. You should check the file permission setting. The standard setting should be 755 directories and 644 for files is strongly recommended for NGINX use.

READ  How to Create a Contact Form with the reCAPTCHA in WordPress

Identify the NGINX User

To begin, you will need to determine what user NGINX is running as. To do this, use the command:

ps -ef | grep nginx

Check the first column, for any of the NGINX worker processes:


In this example, the NGINX worker process is running as the user nginx.

Set File Ownership

Go to the directory above the website’s document root. For example, if your website’s document root is /usr/share/nginx/ go to /usr/share/nginx with the command:

cd /usr/share/nginx

Change the ownership of all the files from this point down to the nginx user with the command:

sudo chown -R nginx:nginx *

Set Permissions

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 directory, the command is:

sudo chmod 755

Then go to the web document root directory:


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

sudo chmod 644 *



(Visited 5,205 times, 5 visits today)
  • 1


I write about Multilingual WordPress, SEO, Website Performance, Plugins and Themes. Also, I like answering WordPress question on Quora. I like to research and review for Wordpress Plugin! Look for me if you have any Wordpress product!

massa elementum elit. amet, facilisis Aliquam quis, consequat.

Pin It on Pinterest

Do you find this interesting?

Share it with your friends!