0

I looked through about 5 questions and blog posts already and tried everything they told me without luck. I can browse to www.example.com/phpinfo.php, but not www.example.com/index.php. I even went so far as to make phpinfo.php a symlink of index.php and phpinfo.php still works while index.php does not.

Nginx Config

[admin@web01 www]$ cat /etc/nginx/conf.d/example.com.conf 
server {
    listen       80;
    server_name  www.example.com;

    # Document root
    index  index.php;
    root   /var/www/sites/example.com/www;

    # Pass PHP scripts to FastCGI server
    location ~* \.php$ {
        include       fastcgi.conf;
        try_files     $uri =404;
        fastcgi_pass  127.0.0.1:9000;
    }
}

[admin@web01 www]$ cat /etc/nginx/fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
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  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;

Permissions

[admin@web01 www]$ ls -al /var/www/sites/example.com/www/*.php
-rw-rw-r--. 1 admin admin 17 Jan 24 10:37 /var/www/sites/example.com/www/index.php
lrwxrwxrwx. 1 admin admin  9 Jan 24 10:37 /var/www/sites/example.com/www/phpinfo.php -> index.php

[admin@web01 www]$ ls -alZ /var/www/sites/example.com/www/*.php
-rw-rw-r--. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/sites/example.com/www/index.php
lrwxrwxrwx. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/sites/example.com/www/phpinfo.php -> index.php

[admin@web01 ~]# ls -al /var
drwxr-xr-x. 19 root root  4096 Dec 15 18:02 .
dr-xr-xr-x. 23 root root  4096 Dec 15 17:48 ..
drwxr-xr-x.  7 root root  4096 Dec 15 18:13 www

[admin@web01 ~]# ls -al /var/www
drwxr-xr-x.  7 root  root  4096 Dec 15 18:13 .
drwxr-xr-x. 19 root  root  4096 Dec 15 18:02 ..
drwxr-xr-x.  7 admin admin 4096 Jan 23 11:35 sites

[admin@web01 ~]# ls -al /var/www/sites
drwxr-xr-x. 7 admin admin 4096 Jan 23 11:35 .
drwxr-xr-x. 7 root  root  4096 Dec 15 18:13 ..
drwxrwxr-x. 4 admin admin 4096 Jan 23 11:21 example.com

[admin@web01 ~]# ls -al /var/www/sites/example.com
drwxrwxr-x.  4 admin admin 4096 Jan 23 11:21 .
drwxr-xr-x.  7 admin admin 4096 Jan 23 11:35 ..
drwxrwxr-x. 10 admin admin 4096 Jan 23 11:21 html
drwxrwxr-x.  2 admin admin 4096 Jan 27 09:00 logs
lrwxrwxrwx.  1 admin admin   11 Jan 23 11:21 www -> html/public

[admin@web01 ~]# ls -al /var/www/sites/example.com/html
drwxrwxr-x. 10 admin admin 4096 Jan 23 11:21 .
drwxrwxr-x.  4 admin admin 4096 Jan 23 11:21 ..
drwxrwxr-x. 11 admin admin 4096 Jan 23 11:21 application
drwxrwxr-x.  8 admin admin 4096 Jan 23 11:21 data
drwxrwxr-x.  3 admin admin 4096 Jan 23 11:21 docs
drwxrwxr-x.  3 admin admin 4096 Jan 23 11:22 library
drwxrwxr-x.  6 admin admin 4096 Jan 27 15:57 public
drwxrwxr-x.  3 admin admin 4096 Jan 24 09:33 scripts
drwxrwxr-x.  4 admin admin 4096 Jan 23 11:21 tests

[admin@web01 ~]# ls -al /var/www/sites/example.com/html/public
drwxrwxr-x.  6 admin admin 4096 Jan 27 15:57 .
drwxrwxr-x. 10 admin admin 4096 Jan 23 11:21 ..
drwxrwxr-x.  4 admin admin 4096 Jan 23 11:21 assets
drwxrwxr-x.  4 admin admin 4096 Jan 23 11:21 css
-rw-rw-r--.  1 admin admin   17 Jan 24 10:37 index.php
drwxrwxr-x.  4 admin admin 4096 Jan 24 09:33 js
lrwxrwxrwx.  1 admin admin    9 Jan 24 10:37 phpinfo.php -> index.php

Error log

2014/01/24 10:37:52 [error] 8286#0: *15 FastCGI sent in stderr:
"Unable to open primary script: /var/www/sites/example.com/www/index.php
(No such file or directory)" while reading response header from upstream,
client: XXX, server: www.example.com, request: "GET /index.php HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "www.example.com"

Update

  1. Updated my config to include everything
  2. Added permissions for /, /var, /var/www, etc
  3. Turned off SELinux completely with no effect

Update #2

Removed the try_files line from the location ... .php$ line and edited php.ini's cgi.fix_pathinfo=0. Realized I hadn't restarted php-fpm this whole time. Magically working now! If you can explain why phpinfo.php was working the whole time and index.php was not (even though they resided in the same directory, and phpinfo.php was a symlink to index.php!!) you get the bounty.

11
  • It could be because include fastcgi_params overrides fastcgi_param SCRIPT_FILENAME.... what if you move include fastcgi_params just before the fastcgi_pass directive ?
    – krisFR
    Jan 24, 2014 at 18:05
  • @user2196728 Thanks for the comment. Unfortunately, no effect.
    – nachito
    Jan 24, 2014 at 18:18
  • My guess is your fastcgi server doesn't have the correct permissions for selinux. Check selinux's audit log to see if it's blocking the file from the php executable.
    – DerfK
    Jan 24, 2014 at 18:48
  • @DerfK Nothing there. Not sure that would explain why phpinfo.php is working and index.php isn't either
    – nachito
    Jan 24, 2014 at 19:39
  • What happens if you point the root directly to: /var/www/sites/example.com/html/public? Does this alter the behavior at all?
    – jaseeey
    Jan 28, 2014 at 5:11

2 Answers 2

1

Try adding this to your nginx.conf:

fastcgi_index index.php;

e.g. the relevant section of your nginx.conf file would look like this:

# Pass PHP scripts to FastCGI server
location ~ \.php$ {
    fastcgi_index index.php;
    include       fastcgi.conf;
    try_files     $uri =404;
    fastcgi_pass  127.0.0.1:9000;
}

What this does is tell fastcgi to use index.php if a file is not specified. For the record, I am using a patched nginx 1.2.9 (I changed ~* to ~ because that's how it looks in my nginx.conf)

-1

In nginx server block conf your root is root /var/www/sites/example.com/www

Path to files is /var/www/sites/example.com/html/public

I know your phpinfo.php works, but try to make paths the same.

Also if phpinfo works, rename that phpinfo.php to index.php and see if it works.

You must log in to answer this question.

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