PHP-FPM在macOS上使用Nginx发送空响应
我在macOS 10.12.4上安装了nginx 1.10.3和PHP5.5.38作为开发服务器 当我在浏览器中尝试测试php文件时,正文为空,但响应标题似乎正常:PHP-FPM在macOS上使用Nginx发送空响应,php,macos,nginx,homebrew,Php,Macos,Nginx,Homebrew,我在macOS 10.12.4上安装了nginx 1.10.3和PHP5.5.38作为开发服务器 当我在浏览器中尝试测试php文件时,正文为空,但响应标题似乎正常: HTTP/1.1200正常 服务器:nginx/1.10.3 日期:2017年3月29日星期三11:35:21 GMT 内容类型:text/html 传输编码:分块 连接:保持活力 X-Powered-By:PHP/5.5.38 php-fpm.log或nginx/error.log中没有错误 我的nginx.conf有: ser
HTTP/1.1200正常
服务器:nginx/1.10.3
日期:2017年3月29日星期三11:35:21 GMT
内容类型:text/html
传输编码:分块
连接:保持活力
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;
}
}
listen = '/usr/local/var/run/php-www.sock'
bob是用于测试的本地主机名,指向etc/hosts中的127.0.0.1
php-fpm.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;
}
}
listen = '/usr/local/var/run/php-www.sock'
知道我做错了什么吗?要使用自制软件安装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
更改:listen8080代码>
到:listen80代码>
要保存并配置并启动NGINX运行:
$ sudo nginx
然后,根据您的问题,您可能只是指向一个空的PHP文件。尝试打印一个phpinfo(),然后查找“DOCUMENT\u ROOT”以查看它的去向。如果没有读取所有配置文件的能力,很难获得帮助
您刚刚发布了一个,不是包含的,也不是php-fpm.conf。这并不是不赞成(一堆配置文件在一个问题上并不太合适),但它只是指出,我们“看不到”的配置文件可能因安装而异
无论如何,我看到了一些与wordpress站点服务器上的配置文件不同的地方
以下是一些提示,考虑到您没有收到任何错误,php fpm正在运行,nginx可以通过套接字与之“通信”(否则您将收到一个坏网关错误)
一开始
server {
listen 80;
server_name wordpress.bob;
root /Users/mark/Sites/wordpress;
index index.php; # <-- ADD THIS
最后一部分
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;
}
如果这一行缺失,php代码将无法读取$\u服务器['SCRIPT\u FILENAME']
,并且(我认为)这可能会破坏wordpress代码,导致输出为空
最后,确保php fpm工作进程具有访问/usr/local/var/run/php-www.sock
通常,套接字具有相同的所有者:工作组
workers用户和组在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 = ......
谢谢,但我的PHP文件中确实有一些内容没有打印。您是否正确设置了根路径?@KonstantinOkhotnick是的,根路径是正确的。我只使用nginx测试了一个HTML文件。我还让Apache使用相同的PHP安装运行,因此我知道它可以工作。您可以尝试使用单个索引将nginx
指向不同的(测试)目录。PHP
文件带有一个简单的谢谢,解决方案是包含fastcgi.conf而不是fastcgi\u参数。用户/组对我没有影响。