简体   繁体   English

nginx和php72:脚本未运行; 也许找不到?

[英]nginx and php72: scripts not running; maybe not found?

I am running a fresh install of FreeBSD (latest stable production version) with nginx and php72 installed from packages. 我正在运行全新的FreeBSD安装(最新的稳定生产版本),并从软件包中安装了nginx和php72。 My first difficulty is that most of the information on the web relates to building these applications from source and the packages put .conf files and other things in different directories. 我的第一个困难是,网络上的大多数信息都与从源代码构建这些应用程序有关,并且程序包将.conf文件和其他内容放置在不同的目录中。 I think I figured that one out with the help of Nginx HTTP Server - Fourth Edition and some browsing. 我想我在Nginx HTTP Server-第四版和一些浏览器的帮助下发现了这一点。 Nginx serves static files just fine. Nginx可以很好地提供静态文件。 But PHP isn't working. 但是PHP无法正常工作。 Every attempt to run a short script containing php-info() results in: 每次尝试运行包含php-info()的简短脚本都会导致:

An error occurred. 发生错误。 Sorry, the page you are looking for is currently unavailable. 抱歉,您要查找的页面当前不可用。 Please try again later. 请稍后再试。 If you are the system administrator of this resource then you should check the error log for details. 如果您是此资源的系统管理员,则应检查错误日志以获取详细信息。 Faithfully yours, nginx. 忠实的,nginx。

I found this Stack Exchange question from several years ago: File Not Found when running PHP with Nginx I tried several of the solutions given in the question, including the ones with 67 and 10 upvotes. 我发现了几年前的这个Stack Exchange问​​题: 使用Nginx运行PHP时找不到文件我尝试了问题中给出的几种解决方案,包括67和10赞成的解决方案。 You can see them in my nginx.conf file below. 您可以在下面的nginx.conf文件中看到它们。 Here is my nginx.conf file: 这是我的nginx.conf文件:

  user  nginx;
    worker_processes auto;
    worker_priority 10;

    # This default error log path is compiled-in to make sure configuration parsing
    # errors are logged somewhere, especially during unattended boot when stderr
    # isn't normally logged anywhere. This path will be touched on every nginx
    # start regardless of error log location configured here. See
    # https://trac.nginx.org/nginx/ticket/147 for more info. 
    #
    error_log  /var/log/nginx/error.log;
    #

    pid        logs/nginx.pid;


    events {
        worker_connections  1024;
    }


    http {
        include       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  logs/access.log  main;

        sendfile        on;
        #tcp_nopush     on;

        #keepalive_timeout  0;
        keepalive_timeout  65;

        #gzip  on;

        server {
            server_name  JRWFreeBSD;
            listen       80;
            root /usr/local/www/nginx/documents;
            index index.html index.htm index.php
            #charset koi8-r;

            #access_log  logs/host.access.log  main;


            error_page  404              /404.html;

            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /usr/local/www/nginx-dist;
            }

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~* \.php$ {
            root /usr/local/www/nginx/documents;
                fastcgi_pass   127.0.0.1:9000;
            #   fastcgi_index  index.php;
                include        fastcgi_params;

            #   fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx/documents$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;

            }
        }
    }
    enter code here

(This nginx.config file is based on the default that shipped with nginx. I have only included the server block I actually use, not the commented-out blocks.) All the files in the documents folder have user nginx / group nginx as the owner, with permissions 755. Nginx loads without reporting errors from any config file, including the one for php-fpm. (此nginx.config文件基于nginx附带的默认值。我只包括了我实际使用的服务器块,没有注释掉的块。)documents文件夹中的所有文件都具有用户nginx / nginx组作为所有者,权限为755。Nginx加载时不会报告任何配置文件(包括php-fpm的配置文件)中的错误。 Nothing showed up in the log files since I got nginx properly configured to serve static files. 由于我已将nginx正确配置为提供静态文件,因此日志文件中没有任何显示。 I have verified that the root path -- /usr/local/www/nginx/documents -- is correct. 我已经验证了根路径-/ usr / local / www / nginx / documents-是正确的。 Nginx serves static files from there. Nginx从那里提供静态文件。 The following script called phpinfo.php is in documents. 以下名为phpinfo.php的脚本在文档中。

  <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>

php - I gave me results that include these lines: PHP-我给我的结果包括这些行:

 Environment
    OLDPWD => /usr/local/etc/nginx
    --snip--
    PWD => /usr/local/www/nginx/documents

    PHP Variables
    $_SERVER['OLDPWD'] => /usr/local/etc/nginx
    --snip--
    $_SERVER['PWD'] => /usr/local/www/nginx/documents

Command line php scripts work. 命令行php脚本有效。

Everything looks right, but php scripts do not run when nginx serves them. 一切看起来都不错,但是当nginx为它们提供服务时,php脚本不会运行。

Solved it! 解决了! sockstat told me that nobody was listening on 127.0.0.1 and while I was looking for a way to fix that I found out that while nginx was sending scripts to that ip address, php-fpm72 was listening on /var/run/php72-fpm.sock sockstat告诉我,没有人在听127.0.0.1,而当我在寻找一种解决方法时,我发现当nginx将脚本发送到该IP地址时,php-fpm72在/ var / run / php72-fpm上进行监听。袜子

I made these changes to nginx.conf: 我对nginx.conf进行了以下更改:

 fastcgi_pass   unix:/var/run/php72-fpm.sock;
 #fastcgi_pass   127.0.0.1:9000;

PHP scripts now work. PHP脚本现在可以使用。 Installing nginx from the FreeBSD pkg system installed a default nginx.conf script that was not compatible with the default .conf script created when I installed php-fpm72 from a pkg. 从FreeBSD pkg系统安装nginx会安装默认的nginx.conf脚本,该脚本与我从pkg安装php-fpm72时创建的默认.conf脚本不兼容。 I still have one question, though: should I file a bug with the pkg maintainers? 不过,我还有一个问题:我应该向pkg维护者提交错误吗?

Edited to add: Thank you Ms Hasse for getting me to re-examine the logs which started me on the right path. 编辑添加:谢谢哈斯女士,让我重新检查启动我的正确路径的日志。 Also, Mr. Gelov, I replaced several of the lines I had with your better-focused version. 另外,Gelov先生,我用重点突出的版本替换了我的几行内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM