PHP-FPM 在 macOS 上使用 Nginx 发送空响应
PHP-FPM sending empty response with Nginx on macOS
我在 macOS 10.12.4
上安装了 nginx 1.10.3 和 php 5.5.38 作为开发服务器
当我在浏览器中尝试测试 php 文件时,body 是空的,但响应 headers 似乎正常:
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Wed, 29 Mar 2017 11:35:21 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.5.38
php-fpm.log 或 nginx/error.log
中没有错误
我的 nginx.conf 有:
server {
listen 80;
server_name wordpress.bob;
root /Users/mark/Sites/wordpress;
include /usr/local/etc/nginx/global_restrictions.conf;
include /usr/local/etc/nginx/wordpress.conf;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/usr/local/var/run/php-www.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
wordpress.bob 是本地主机名,用于测试指向 etc/hosts
中的 127.0.0.1
php-fpm.conf 有:
listen = '/usr/local/var/run/php-www.sock'
知道我做错了什么吗?
使用 Homebrew 安装 NGINX:
$ brew install nginx
运行 NGINX:
$ sudo nginx
测试本地主机 nginx :
http://localhost:8080
NGINX 配置文件应该在:
$ /usr/local/etc/nginx/nginx.conf
如果要更改默认端口:
$ sudo nginx -s stop
$ vim /usr/local/etc/nginx/nginx.conf
更改:listen 8080;
收件人:listen 80;
保存并配置并启动 NGINX 运行 :
$ sudo nginx
然后,根据您的问题,您可能只是指向一个空的 PHP 文件。尝试打印一个 phpinfo() 然后寻找 "DOCUMENT_ROOT" 看看它去了哪里。
没有读取所有配置文件的能力,很难提供帮助。
您刚刚发布了一个,不是包含的,也不是 php-fpm.conf。这不是不赞成(配置文件墙在问题中不太合适),只是指出我们 "don't see" 的配置文件可能因安装而异。
无论如何,我发现与我在 wordpress 站点的服务器上的配置文件有些不同。
考虑到您没有收到任何错误,这里有一些提示 php-fpm 是 运行 和 nginx 可以通过套接字 "communicate" 到它(否则你会得到一个 错误的网关 错误)。
一开始...
server {
listen 80;
server_name wordpress.bob;
root /Users/mark/Sites/wordpress;
index index.php; # <-- ADD THIS
确保在随附的 wordpress.conf
中您有
location / {
try_files $uri $uri/ /index.php?$args;
}
最后一部分...
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 512k;
fastcgi_intercept_errors on;
fastcgi_max_temp_file_size 0;
fastcgi_connect_timeout 3s;
fastcgi_send_timeout 5s;
fastcgi_read_timeout 5s;
include fastcgi.conf; # <--- fastcgi.conf, NOT fastcgi_params
fastcgi_pass /usr/local/var/run/php-www.sock;
}
fastcgi.conf 和 fastcgi_params 之间的区别(在我的安装中)只有一行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
如果缺少这一行 php 代码无法读取 $_SERVER['SCRIPT_FILENAME']
并且(我认为)这可能会破坏 wordpress 代码导致空输出。
最后确保php-fpm工作进程有权限访问/usr/local/var/run/php-www.sock
通常socket有相同的owner:group个worker
工人用户和组设置在php-fpm.conf:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = ......
group = ......
我在 macOS 10.12.4
上安装了 nginx 1.10.3 和 php 5.5.38 作为开发服务器当我在浏览器中尝试测试 php 文件时,body 是空的,但响应 headers 似乎正常:
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Wed, 29 Mar 2017 11:35:21 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.5.38
php-fpm.log 或 nginx/error.log
中没有错误我的 nginx.conf 有:
server {
listen 80;
server_name wordpress.bob;
root /Users/mark/Sites/wordpress;
include /usr/local/etc/nginx/global_restrictions.conf;
include /usr/local/etc/nginx/wordpress.conf;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/usr/local/var/run/php-www.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
wordpress.bob 是本地主机名,用于测试指向 etc/hosts
中的 127.0.0.1php-fpm.conf 有:
listen = '/usr/local/var/run/php-www.sock'
知道我做错了什么吗?
使用 Homebrew 安装 NGINX:
$ brew install nginx
运行 NGINX:
$ sudo nginx
测试本地主机 nginx :
http://localhost:8080
NGINX 配置文件应该在:
$ /usr/local/etc/nginx/nginx.conf
如果要更改默认端口:
$ sudo nginx -s stop
$ vim /usr/local/etc/nginx/nginx.conf
更改:listen 8080;
收件人:listen 80;
保存并配置并启动 NGINX 运行 :
$ sudo nginx
然后,根据您的问题,您可能只是指向一个空的 PHP 文件。尝试打印一个 phpinfo() 然后寻找 "DOCUMENT_ROOT" 看看它去了哪里。
没有读取所有配置文件的能力,很难提供帮助。
您刚刚发布了一个,不是包含的,也不是 php-fpm.conf。这不是不赞成(配置文件墙在问题中不太合适),只是指出我们 "don't see" 的配置文件可能因安装而异。
无论如何,我发现与我在 wordpress 站点的服务器上的配置文件有些不同。
考虑到您没有收到任何错误,这里有一些提示 php-fpm 是 运行 和 nginx 可以通过套接字 "communicate" 到它(否则你会得到一个 错误的网关 错误)。
一开始...
server {
listen 80;
server_name wordpress.bob;
root /Users/mark/Sites/wordpress;
index index.php; # <-- ADD THIS
确保在随附的 wordpress.conf
中您有
location / {
try_files $uri $uri/ /index.php?$args;
}
最后一部分...
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_buffer_size 128k;
fastcgi_buffers 256 16k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 512k;
fastcgi_intercept_errors on;
fastcgi_max_temp_file_size 0;
fastcgi_connect_timeout 3s;
fastcgi_send_timeout 5s;
fastcgi_read_timeout 5s;
include fastcgi.conf; # <--- fastcgi.conf, NOT fastcgi_params
fastcgi_pass /usr/local/var/run/php-www.sock;
}
fastcgi.conf 和 fastcgi_params 之间的区别(在我的安装中)只有一行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
如果缺少这一行 php 代码无法读取 $_SERVER['SCRIPT_FILENAME']
并且(我认为)这可能会破坏 wordpress 代码导致空输出。
最后确保php-fpm工作进程有权限访问/usr/local/var/run/php-www.sock
通常socket有相同的owner:group个worker
工人用户和组设置在php-fpm.conf:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = ......
group = ......