当我尝试访问
- domain.com/status/show 或
- domain.com/status/ping,
我在 nginx 中收到以下错误:
2024/08/24 19:36:11 [error] 7448#0: *13203 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 15.16.2.54, server: domain.com, request: "GET /status/show HTTP/1.1", upstream: "fastcgi://unix:/usr/local/php74/sockets/domain.com:", host: "domain.com"
我在其他服务器上使用相同的配置,它运行正常,没有任何问题。唯一的区别是 PHP 版本是 PHP 8.2。
由于某种原因,在此装有 PHP 7.4 的服务器上,相同的配置不起作用。
我尝试了很多方法,但都没有什么效果,而且我也没什么主意了。
注意,我特别检查了状态页面是否存在于 PHP 8.0 之前,并且它从 PHP 5.3 开始就存在。
我的 php-fpm 配置文件是:
[domain.com]
user = www
group = www
listen = sockets/domain.com
listen.owner = www
listen.group = www
listen.mode = 0660
include = etc/common.conf
;access.format is in common
access.log = var/log/$pool.access.log
; The log file for slow requests
slowlog = var/log/$pool.slow.log
; The timeout for serving a single request after which a PHP backtrace will be
request_slowlog_timeout = 10s
通用配置文件
; Note: This value is mandatory.
pm = dynamic
pm.max_children = 800
;pm.start_servers = 8
pm.min_spare_servers = 16
pm.max_spare_servers = 32
pm.process_idle_timeout = 90s;
; The number of requests each child process should execute before respawning.
pm.max_requests = 10000
pm.status_path = /status/show
ping.path = /status/ping
access.format = "\"%R\" - %{REMOTE_ADDR}e - %{HTTP_CF_CONNECTING_IP}e - %u [%t] \"%m %r%Q%q\" \"%{REQUEST_URI}e\" %s %l %M %d"
nginx 主机
server {
listen 80;
listen 443 ssl http2;
server_name domain.com www.domain.com;
root /www/sites/domain.com;
location ~ ^/index\.php(/|$) {
fastcgi_pass unix:/usr/local/php74/sockets/domain.com;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
internal;
}
location ~ .\.php(/|$) {
fastcgi_pass unix:/usr/local/php74/sockets/domain.com;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~* ^/status/(show|ping)(/|$) {
fastcgi_pass unix:/usr/local/php74/sockets/domain.com;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
}
location / {
try_files $uri $uri/ $uri/index.php /index.php$is_args$query_string;
}
}
fastcgi配置文件
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_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
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;
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;
事实证明,配置没有设置以下参数:
一旦我添加它,它就可以正常工作。
有趣的是,这只破坏了这个 URL
/status/show
,没有破坏其他内容。