nginx 403 Forbidden on CentOS (Vagrant)

2

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?

user1502178

Posted 2014-10-30T06:19:59.530

Reputation: 191

Is SELinux set to enforcing? – aairey – 2014-10-30T12:13:38.340

@aairey SELinux is disabled. (sestatus) – user1502178 – 2014-10-30T12:27:54.673

Enabled SELinux, still getting 403. – user1502178 – 2014-10-30T13:24:25.477

Check your error log. – Michael Hampton – 2014-10-30T16:07:54.323

@MichaelHampton nginx error and access logs are empty. – user1502178 – 2014-10-30T17:15:34.720

@user1502 Reduce error log level. I think we won't go far without your nginx configuration too. – Xavier Lucas – 2014-10-30T17:45:55.130

@XavierLucas added the conf, how to reduce the log level? Do you mean add debug, e.g error_log /path/to/log debug; ? – user1502178 – 2014-10-31T05:14:05.023

Answers

2

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.

Alasdair Dougall

Posted 2014-10-30T06:19:59.530

Reputation: 21

0

What is the content of /var/www/awesome/ and its permissions?

If there is no index.html, index.htm or index.php file, nginx will be attempting to list directory content, which is by default forbidden (cf. autoindex documentation).

Bernard Rosset

Posted 2014-10-30T06:19:59.530

Reputation: 246