nginx和php72:脚本未运行;也许找不到?
我正在运行FreeBSD(最新稳定生产版本)的新安装,其中nginx和php72是从软件包中安装的。我的第一个困难是,web上的大多数信息都与从源代码构建这些应用程序有关,包将.conf文件和其他内容放在不同的目录中。我想我是在Nginx HTTP服务器第四版和一些浏览的帮助下找到的。Nginx可以很好地提供静态文件。但是PHP不起作用。每次尝试运行包含php-info()的短脚本都会导致: 发生了一个错误。很抱歉,您正在查找的页面当前为空 不可用的请稍后再试。如果你是系统的 然后,您应该检查错误日志以了解 细节。你忠实的,nginx 我在几年前发现了这个堆栈交换问题: 我尝试了问题中给出的几种解决方案,包括67票和10票赞成的方案。您可以在下面我的nginx.conf文件中看到它们。这是我的nginx.conf文件:nginx和php72:脚本未运行;也许找不到?,php,nginx,freebsd,Php,Nginx,Freebsd,我正在运行FreeBSD(最新稳定生产版本)的新安装,其中nginx和php72是从软件包中安装的。我的第一个困难是,web上的大多数信息都与从源代码构建这些应用程序有关,包将.conf文件和其他内容放在不同的目录中。我想我是在Nginx HTTP服务器第四版和一些浏览的帮助下找到的。Nginx可以很好地提供静态文件。但是PHP不起作用。每次尝试运行包含php-info()的短脚本都会导致: 发生了一个错误。很抱歉,您正在查找的页面当前为空 不可用的请稍后再试。如果你是系统的 然后,您应该检查错
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
(这个nginx.config文件基于nginx附带的默认值。我只包含了我实际使用的服务器块,而不是注释掉的块。)
documents文件夹中的所有文件的所有者都是用户nginx/group nginx,权限为755。Nginx从任何配置文件加载而不报告错误,包括用于php fpm的配置文件。自从我将nginx正确配置为服务静态文件以来,日志文件中没有显示任何内容。
我已经验证了根路径--/usr/local/www/nginx/documents--是正确的。Nginx从那里提供静态文件。
以下名为phpinfo.php的脚本位于文档中
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
命令行php脚本可以工作
看起来一切正常,但当nginx为php脚本提供服务时,php脚本不会运行。解决了这个问题!sockstat告诉我没有人在监听127.0.0.1,当我在寻找修复方法时,我发现当nginx向该ip地址发送脚本时,php-fpm72正在监听/var/run/php72-fpm.sock 我对nginx.conf做了以下更改:
fastcgi_pass unix:/var/run/php72-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
PHP脚本现在可以工作了。从FreeBSD pkg系统安装nginx时安装了一个默认nginx.conf脚本,该脚本与我从pkg安装php-fpm72时创建的默认.conf脚本不兼容。不过,我还有一个问题:我应该向pkg维护人员提交一个bug吗
编辑添加:谢谢Hasse女士让我重新检查日志,让我走上了正确的道路。另外,盖洛夫先生,我用你的重点更明确的版本替换了我的几行代码。你的服务器的错误日志告诉你关于那次失败的信息是什么?在我的配置中,都有
fastcgi\u param SCRIPT\u FILENAME$request\u FILENAME
和fastcgi\u参数SCRIPT\u NAME$fastcgi\u SCRIPT\u NAME
,以及fastcgi\u split\u path\u info^(.+\.php)(/.+)$代码>这来自error.log:2019/02/01 05:51:36[错误]83774#100093:*1 kevent()报告连接到上游时connect()失败(61:连接被拒绝),客户端:192.168.1.7,服务器:jrwfreebsd,请求:“GET/phpinfo.php HTTP/1.1”,上游:fastcgi://127.0.0.1:9000,主机:“192.168.1.12”2019/02/01 06:10:46[错误]5702#100147:*1 kevent()报告连接上游时connect()失败(61:连接被拒绝),客户端:192.168.1.7,服务器:jrwfreebsd,请求:“GET/phpinfo.php HTTP/1.1”,上游:fastcgi://127.0.0.1:9000,主机:“192.168.1.12”
fastcgi_pass unix:/var/run/php72-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;