title: Why can't I have my own custom root directive in nginx
body: <p><strong>OS:</strong> Centos7</p>
  
  <p><strong>Nginx:</strong> 1.9.14</p>
  
  <p>Please consider this simple server block</p>
  
  <pre><code>server {
      listen 80;
      server_name website.com;
      root /usr/share/nginx/html;
      index       index.php index.html index.htm;
  
      location / {
          try_files $uri $uri/ /index.php?$args;
      }
  
      location ~ \.php$ {
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
          include        fastcgi_params;
      }
  }
  </code></pre>
  
  <p>I have scoured the net trying to figure this one out. The above configuration works. Located at the root directive is a file called index.php and contains this line</p>
  
  <pre><code>&lt;?php phpinfo();
  </code></pre>
  
  <h2>Navigating to the site reveals PHPINFO. So this confirms that PHP is working correctly however..</h2>
  
  <p><strong>Let's say I want to change my root directive to;</strong></p>
  
  <pre><code>root /steven/html;
  </code></pre>
  
  <p>Inside this location the same index.php file resides. But instead of PHPINFO I get;</p>
  
  <pre><code>File not found.
  </code></pre>
  
  <p>All I did was change the root directive, because that is where I'd rather put my files..  The <strong>/var/log/nginx/error.log</strong> reveals;</p>
  
  <pre><code>2016/05/24 04:03:41 [error] 473#473: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 125.238.2.111, server: website.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "website.com"
  </code></pre>
  
  <ul>
  <li>Folder permissions for /usr/share/nginx/html are all root:root 755</li>
  <li>Folder permissions for /steven/html are also root:root 755</li>
  </ul>
  
  <h3>Anyone got an idea why? I would really appreciate an eye opener here.</h3>
  
  <p>I know the following will be asked so I will include these.</p>
  
  <p><strong>Nginx compiled from source</strong></p>
  
  <pre><code>nginx version: nginx/1.9.14
  built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
  built with OpenSSL 1.0.2g  1 Mar 2016
  TLS SNI support enabled
  configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --add-module=/root/custom-nginx/nginx-1.9.14/src/http/modules/ngx_cache_purge/ --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module --without-http_memcached_module --with-openssl=../../openssl-1.0.2g --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic'
  </code></pre>
  
  <p><strong>Contents of fastcgi_params</strong></p>
  
  <pre><code>fastcgi_param  QUERY_STRING       $query_string;
  fastcgi_param  REQUEST_METHOD     $request_method;
  fastcgi_param  CONTENT_TYPE       $content_type;
  fastcgi_param  CONTENT_LENGTH     $content_length;
  
  fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
  fastcgi_param  REQUEST_URI        $request_uri;
  fastcgi_param  DOCUMENT_URI       $document_uri;
  fastcgi_param  DOCUMENT_ROOT      $document_root;
  fastcgi_param  SERVER_PROTOCOL    $server_protocol;
  fastcgi_param  REQUEST_SCHEME     $scheme;
  fastcgi_param  HTTPS              $https if_not_empty;
  
  fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
  fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
  
  fastcgi_param  REMOTE_ADDR        $remote_addr;
  fastcgi_param  REMOTE_PORT        $remote_port;
  fastcgi_param  SERVER_ADDR        $server_addr;
  fastcgi_param  SERVER_PORT        $server_port;
  fastcgi_param  SERVER_NAME        $server_name;
  
  # PHP only, required if PHP was built with --enable-force-cgi-redirect
  fastcgi_param  REDIRECT_STATUS    200;
  </code></pre>
  
  <p><strong>Sanity check</strong></p>
  
  <pre><code>[root@ip-172-31-2-48 /]# ls -l /steven/html
  total 4
  -rw-r--r--. 1 root root 17 May 24 03:49 index.php
  </code></pre>