403 Forbidden in nginx on Centos 7

November 29, 2017 13.1k views
Nginx CentOS WordPress

Having issues when I moved files from my old host to a Centos 7 droplet where when you visit those directories in a browser return a 403: Forbidden response.

The nginx error log shows the same thing, where permission is denied.

I have done the following to attempt to fix the nginx permissions:

cd /var/www
sudo chown -R nginx:nginx /var/www
find . -type d -exec chmod 755 {} \;  # Change directory permissions rwxr-xr-x
find . -type f -exec chmod 644 {} \;  # Change file permissions rw-r--r--

The resulting ls -lhA command shows nginx as the owner.

Nevertheless, a 403 persists.

I’ve sudo systemctl restart nginx php-fpm several times as well.

Configuration file contents
/etc/nginx/conf.d/default.conf
/etc/nginx/nginx.conf
/etc/php-fpm.d/www.conf
/etc/php.ini


I believe those are all the config files. If someone needs to look at something else I can provide it

1 comment
2 Answers

Hello,

After checking your config file and your permissions along with the logs that you’ve provided, I am pretty sure that the problem is due to an incorrect index file. This is actually one of the most common cause for 403 errors.

In your Nginx configuration file you have specified which index files should be loaded, and in which order:

index index.php index.html index.htm;

If none of those three files are found in the directory, Nginx would return a “403 Forbidden” error. According to the logs you are trying to access a folder called /var/www/html/stefano/ and you are getting a 403 so most likely you do not have a index file in that directory.

Hope that this helps!
Bobby

run
setenforce permissive
if you have SELinux enabled

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!