2

For some reason I cannot change the root. I have the same rights as the default root on /usr/share/nginx/html, and I also have 755 recursive on all files and folders in my other folder. I even tried changing the user and group to root and nginx back and forth to see if it made any difference but it doesn't. I keep getting 403 Forbidden

so basicly I made this folder

$ mkdir -p /srv/www/test.com/public_html

$ vi /srv/www/test.com/public_html/index.html

$ vi /srv/www/test.com/public_html/test.php

$ chmod -R 755 /srv/www/test.com/public_html

tried to change the user and group to nginx

$ chown -R nginx:nginx /srv/www

configured the main conf file

$ vi /etc/nginx/nginx.conf

this is how my config looks like, the includes are commented out

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log;   
pid        /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    index index.php index.html index.htm;

    server {

        listen       80;
        server_name  _;
        root /srv/www/test.com/public_html;
        # root  /usr/share/nginx/html;

        location / {
                autoindex on;
        }

        error_page  404 /404.html;

        location = /40x.html { }


        error_page   500 502 503 504  /50x.html;

        location = /50x.html { }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass   unix:/var/run/php-fpm/www.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }

    }

}       

everything works in the default root folder that is commented out, but when I change the root I get 403 forbidden. I feel like I have tried everything I can, changing users and file permissions and so on. the php-fpm has nginx as user and group. and the user is set to nginx in the main.conf file. I only use this one file for configuration for nginx, and have the includes commented out.

I have no idea what to do. Been stuck for hours now. Any help would be greatly appreciated

8
  • What's in your error log ? What's your test request ? Feb 23, 2015 at 11:49
  • 2015/02/23 12:44:00 [error] 2869#0: *1 "/srv/www/test.com/public_html/index.html" is forbidden (13: Permission denied), client: 192.168.1.230, server: _, request: "GET / HTTP/1.1", host: "192.168.1.202"
    – Alex
    Feb 23, 2015 at 11:56
  • What's the output of ls -lh /srv/www/test.com/public_html/index.html ? Do you have SELinux running enforcing mode ? Feb 23, 2015 at 11:59
  • -rw-r--r--. 1 root root 91 Feb 23 11:15 /srv/www/test.com/public_html/index.html
    – Alex
    Feb 23, 2015 at 12:01
  • i changed it all to root root like the default "root path"
    – Alex
    Feb 23, 2015 at 12:02

1 Answer 1

6

For clarity I'm posting my comment as answer, this was caused by SELinux and setting policy mode to permissive with semanage permissive -a httpd_t is one "quick and dirty" solution.

The clean solution would be to set the SELinux context chcon -Rt httpd_sys_content_t /srv/www/test.com and look for potential new SELinux complaints if any (depends on what you set next in your configuration file).

3
  • 2
    restorecon would work as well, since that's the default context for /srv/www. Feb 23, 2015 at 13:23
  • @MichaelHampton Good point indeed. Feb 23, 2015 at 13:45
  • thank you for the answer, sorry for not accepting answer, I didn't see it before now. thanks!
    – Alex
    Mar 24, 2015 at 21:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .