我已经在 上安装了 nginx、php-fpm 和 php56 OS X EL CAPITAN
。我使用ps
命令来检查 nginx 和 fpm 是否正在运行。
我已将以下代码块添加server
到 nginX 中:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
nginX listen on8080
和 fpm on 9000
。我使用lsof
命令来检查:
php-fpm 22903 root 0u IPv4 0x5a9bc9209264e227 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 22904 fc 0u IPv4 0x5a9bc9209264e227 0t0 TCP 127.0.0.1:9000 (LISTEN)
nginx 22931 fc 6u IPv4 0x5a9bc9208c304cc7 0t0 TCP *:8080 (LISTEN)
nginx 22932 fc 6u IPv4 0x5a9bc9208c304cc7 0t0 TCP *:8080 (LISTEN)
关于为什么 nginx 下载 php 文件而不是解释它们的问题,有什么线索吗?
编辑1:
完整的 nginX 配置:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ \.php$ {
root /usr/local/var/www/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
include servers/*;
我获取的 URL 是:http://localhost:8080/info.php
有人对这个问题有任何线索吗?我问了每一个问题,但stackoverflow
没有成功:
http://serverfault.com/questions/563285/nginx-with-php-fpm-downloading-php-files-rather-than-executing-them-on-mac-os-x?rq=1
http://serverfault.com/questions/412079/nginx-php-fpm-php-file-not-found-cant-figure-out-why?rq=1
答案1
我刚刚更改了下面这一行:
fastcgi_param SCRIPT_FILENAME $scripts$fastcgi_script_name;
到:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
它现在可以工作了。