Question

403 Forbidden in nginx on Centos 7

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

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

run setenforce permissive if you have SELinux enabled

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