douhuan6157 2014-09-22 12:06
浏览 32

FPM / Nginx:无法打开主脚本

I'm struggling to get NGINX and PHP-FPM to talk effectively. My NGINX configuration file includes the following definition for the api offset:

    location /api {
        try_files $uri /api/index.php$is_args$args;
        gzip    off;
        fastcgi_pass    PHP:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_keep_conn off; 
        include         fastcgi_params;
    }

and on my PHP machine I have the following Pool configuration:

[api]
listen = 9000
user = www-data
group = www-data
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.status_path = /status

I then tail the NGINX server's log file and when hitting the webserver with:

http://localhost/api
# or 
http://localhost/api/index.php
# or ...
http://localhost/api/resources.json

I can see from the NGINX server log that NGINX is correctly matching the /api pattern but i get the following errors:

[error] 14#0: *1 FastCGI sent in stderr: "Unable to open primary script: /app/html/websites/couchbase/api/index.php (No such file or directory)"

Where the root directory on the PHP machine is /app/html/websites/couchbase. I'm at a complete loss on what this error really means or more importantly how to debug it from here. Any help would be greatly appreciated.

p.s. I have tried replacing $document_root reference in the fast_cgi_param to hard coded values to see if it makes a difference. It does in the sense that if I point it at an incorrect directory it gives me a No input file specified. error. The only place where I get the error is when it seemingly is pointed to the right place.


Added this in case it helps clarify ... this is the file system at /app/html/websites/couchbase/api on the PHP/FPM machine.

filesystem

I created the test.php file which basically just echo's "Ok" back but that works no better than the primary goal of running index.php.

note: I wasn't sure if execution permissions were important -- as you can see test.php does not have them set in the picture -- but I've tried them both ways and it appears to make no difference.

  • 写回答

1条回答 默认 最新

  • dqx76962 2014-09-22 13:25
    关注

    The error is complaining about the index.php file not found in the root directory. Is it under ...couchbase/api or is in under .../couchbase? In the second case you can fix this problem with a redirection.

    I think you can move try_files outside the location block. I never used $is_args and $args in this kind of redirection, and I've not tested it but IMHO I think you can remove it.

    I think you can fix this problem with this configuration:

    root /app/html/websites/couchbase;
    
    try_files $uri /api/index.php$is_args$args;
    
    location /api {
        rewrite /api/(.*) $1 break;
        gzip    off;
        fastcgi_pass    PHP:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_keep_conn off; 
        include         fastcgi_params;
    }
    

    You can have a cleaner config file if you'll include the following directives:

        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_keep_conn off; 
    

    inside the fastcgi_params file.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大