Mar*_*son 4 php macos homebrew nginx
我在macOS 10.12.4上安装了nginx 1.10.3和php 5.5.38作为开发服务器
当我在浏览器中尝试测试php文件时,正文为空,但响应标题似乎正常:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
wordpress.bob是一个本地主机名,用于测试指向etc/hosts中的127.0.0.1
php-fpm.conf有:
listen = '/usr/local/var/run/php-www.sock'
Run Code Online (Sandbox Code Playgroud)
我有什么想法我做错了吗?
如果无法读取所有配置文件,就很难提供帮助。
您刚刚发布了一个,而不是包含的那些,也不是 php-fpm.conf。这并不是不赞成(一堵墙的配置文件在问题中不太合适),只是指出我们“看不到”的配置文件可能因安装而异。
无论如何,我发现与 wordpress 站点服务器上的配置文件存在一些差异。
这里有一些提示,因为您没有收到任何错误php-fpm正在运行,并且nginx可以通过套接字与它“通信”(否则您会收到错误的网关错误)。
一开始...
server {
listen 80;
server_name wordpress.bob;
root /Users/mark/Sites/wordpress;
index index.php; # <-- ADD THIS
Run Code Online (Sandbox Code Playgroud)
确保在wordpress.conf你有
location / {
try_files $uri $uri/ /index.php?$args;
}
Run Code Online (Sandbox Code Playgroud)
最后一部分...
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;
}
Run Code Online (Sandbox Code Playgroud)
fastcgi.conf和fastcgi_params(在我的安装中)之间的区别只有一行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
Run Code Online (Sandbox Code Playgroud)
如果缺少这一行,php 代码将无法读取$_SERVER['SCRIPT_FILENAME']并且(我认为)这可能会破坏 wordpress 代码,从而导致空输出。
最后确保 php-fpm 工作进程有访问权限 /usr/local/var/run/php-www.sock
通常套接字具有相同的所有者:工人组。
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 = ......
Run Code Online (Sandbox Code Playgroud)