Fix NGINX 403 forbidden error after changing Root directory

Updated on November 12, 2017

Installed Nginx and PHP-FPM for processing PHP files on CentOS server. To my surprise when accessed PHP files through browser, I see “NGINX 403 forbidden error”. Here’s the error message from NGINX error log /var/log/nginx/error.log.

[error] 11044#11044: *4 "/home/html/index.php" is forbidden (13: Permission denied)

I have followed the NGINX installation tutorial. The only deviation from the guide is the root directory is been changed to my home directory. So how did I fix this error? Read below.

How to Fix NGINX 403 forbidden

After googling, found few people suggesting to disable SELinux, which is a bad Idea! It means, you are shutting off one of the security feature. Seriously, stop disabling SELinux, as it is designed to help protect your server from serious security holes. Dan Walsh explains better on why SELinux shouldn’t be disabled.

For. eg., if you run a web server and have some “vulnerable” code that allows for an attacker to run arbitrary commands then SELinux can help mitigate this, by preventing your web server from accessing files it’s not allowed to see. 

Instead follow the below:

sudo chmod o+x /home/html

The above command provides others- that is, people who don’t own /home/html and aren’t in its group owner either — execute permissions on /home/html. This will allow the user who’s running NGINX daemon to execute the files under /home/html.

Restart the nginx daemon as shown below:

sudo systemctl restart nginx


sudo service nginx restart

Hope this tip will help and now the 403 forbidden error will vanish, allowing you to see the actual page.

Was this article helpful?

Related Articles

Leave a Comment