【问题标题】:Failed to setup php on nginx on mac ox无法在 macOS 上的 nginx 上设置 php
【发布时间】:2017-02-07 04:52:03
【问题描述】:

我尝试设置 nginx 在 mac os 上为 php 网站提供服务。但是当我从浏览器打开一个 php 文件时,它会显示一个空白页面而没有任何错误。我已经安装了 php 和 nginx 相关的应用程序。下面是我的php文件:

<?php
 phpinfo(); 
?>

下面是我的 nginx 配置文件:

http{
        server{
                listen  8082;
                root /Users/joey/tmp;
        location / {
            index  index.html index.htm index.php;
        }
                location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
                include /usr/local/etc/nginx/fastcgi_params;
                        autoindex on;
                }


        }
}
events {
    worker_connections  1024;
}

我已经验证 php-fpm 已经启动并监听了 9000 端口:

$ lsof -Pni4 | grep LISTEN | grep php
php-fpm   43310 joey    6u  IPv4 0xdcff1b2732b9c88d      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   43311 joey    0u  IPv4 0xdcff1b2732b9c88d      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   43312 joey    0u  IPv4 0xdcff1b2732b9c88d      0t0  TCP 127.0.0.1:9000 (LISTEN)
php-fpm   43313 joey    0u  IPv4 0xdcff1b2732b9c88d      0t0  TCP 127.0.0.1:9000 (LISTEN)

下面是我的php和nginx版本:

$ nginx -v
nginx version: nginx/1.10.2
$ php -version
PHP 5.6.29 (cli) (built: Dec  9 2016 07:03:56) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

我的配置有什么问题吗?

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    经过一番搜索,我发现我需要在 nginx.conf 文件上进行以下配置才能启用 php 请求:

    location ~ \.php$ {
                            fastcgi_pass 127.0.0.1:9000;
                            fastcgi_param REQUEST_METHOD $request_method;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                            fastcgi_index index.php;
                            include /usr/local/etc/nginx/fastcgi_params;
                            autoindex on;
                    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-31
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多