How to fix 403 forbidden error in Nginx?

H

This post contains affiliate links. If you click through and make a purchase, I may receive a commission (at no additional cost to you). This helps support the blog and allows me to continue to make free content. Thank you for your support!


 

403 access forbidden error message is displayed on the browser when you try to open a file whose public access has been blocked by the webmaster or because of a permission problem. In other words, the web server is saying that you are not allowed to view the file.

If you’re a webmaster (blogger) and if you’re facing this issue, then it ‘s obvious that you don’t have much experience in web server configuration and management. There’s nothing to be ashamed of. Let’s understand these two issues in detail.

IP blocked from accessing a file or directory

There may be some files or directories on the server which the webmaster don’t want the user to access. Nginx configuration file can be configured do so.

The webmaster may have added code to allow only his IP Address to access the file. When you try to access this file, 403 response will be generated, and the browser will show access forbidden error.

If you don’t want to see the error, you can add:

  • A rule to prevent search engine’s access to a particular directory or a file on the server.
  • Whitelist your IP Address.

If the page on your website shouldn’t be crawled and indexed by the search engines, add a disallow rule in the robots.txt file to do so. If the web page is a login page, you should protect it from hackers by adding a rule in the Nginx config file to allow only your IP to access the page.

403 forbidden nginx wordpress fix

Permission Denied

While setting up a content management system, you may have forgotten to make Nginx the owner of the www folder. In such cases, Nginx may not be able to store files on the disk, support editing of files on the server from the CMS dashboard due to which Nginx will return 403 forbidden error. Assign RWX permissions to Nginx to avoid this issue.

If you’re not able to upload media files in WordPress, the above solution will fix the problem. Use the following code for making  Nginx processes the owner of the folder in which your website’s files have been stored:

chown -R nginx:nginx folder_name

You can avoid the 403 forbidden issue by using shared hosting service (Bluehost or Hostgator) or making changes as we have pointed above.

Conclusion: Fixing the 403 error in Nginx is not a big task. You just have to edit the site’s configuration file or make changes to the folder permissions. Make sure that you backup the files before editing it.

About the author

Pramod

My name is Pramod. I’m a software developer (with good knowledge on PHP, JAVA – Android, JavaScript, CSS), blogger and online marketing professional. I’ve 3 years of experience as a blogger and 2 years of full time experience as a software developer.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me