Centos – nginx 403 Forbidden on CentOS (Vagrant)

centosnginxvagrant

What I have checked so far:

Logs – they are empty, booted a new VM.

Permissions:

$ namei -l /var/www/awesome/    
f: /var/www/awesome/    
dr-xr-xr-x root     root     /    
drwxr-xr-x root     root     var    
drwxrwxr-x www-data www-data www
drwxrwxr-x www-data www-data awesome

Given 777 to the host OS folder that has the vagrant file.

Enabled SELinux.

Still, even inside the vm with curl localhost I get a 403.

Here is the nginx configuration for awesome.dev

server {
   listen                *:80;

   server_name           awesome.dev www.awesome.dev;
     index  index.html index.htm index.php;

   access_log            /var/log/nginx/awesome.dev.access.log;
   error_log             /var/log/nginx/awesome.dev.error.log;

   location / {
     root  /var/www/awesome;
     try_files $uri $uri/ index.php /index.php$is_args$args;
   }
   location ~ \.php$ {
     root  /var/www/awesome;
     index  index.html index.htm index.php;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME $request_filename;
     fastcgi_param APP_ENV dev;
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_split_path_info ^(.+\.php)(/.*)$;
     include fastcgi_params;
   }
   sendfile off;
 }

How to fix this?

Best Answer

Had the same issue with CentOS 7. Resolved by:

Check getenforce

This should show 'Enforcing'

Then I ran chcon to change the httpd security context to allow access.

chcon -Rt httpd_sys_content_t /path/to/web/content

Reload Nginx

systemctl restart nginx

Now my pages load.

Related Question