How to Solve 403 forbidden NGINX

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
5 (100%) 4 votes

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/test.example.com.conf
  • Ubuntu 16.04 sudo nano /etc/nginx/sites-available/test.example.com.conf

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  What is Google Analytics

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 index.py to the rundown of perceived file documents, alter this line to peruse:

index index.html index.htm index.php index.py;

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  Local by Flywheel (formerly Pressmatic) - The Best WordPress Development Tool

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/example.com 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 example.com directory, the command is:

sudo chmod 755 example.com

Then go to the web document root directory:

cd example.com

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

sudo chmod 644 *

 

 

(Visited 17 times, 1 visits today)
  • 1
    Share

Admin

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! https://wpcolt.com/advertise/

facilisis luctus id, velit, leo. mattis felis Donec Aenean in quis, nec

Pin It on Pinterest

Do you find this interesting?

Share it with your friends!