【问题标题】:unable to implement php with nginx无法用 nginx 实现 php
【发布时间】:2013-01-26 18:02:29
【问题描述】:

我让 nginx 与 arch linux 一起工作。我在添加 php 和 fastcgi 时遇到问题。我安装了 php 和 php-fpm 软件包。 php-fpm 服务已开启。当我访问带有 php 扩展名的文件时,浏览器会显示 nginx 错误页面,并且添加了以下 nginx 错误日志消息:

2013/01/02 22:39:43 [错误] 721#0: *27 connect() 在连接到上游时失败(111:连接被拒绝),客户端:192.168.1.13,服务器:localhost,请求:“ GET /index.php HTTP/1.1”,上游:“fastcgi://127.0.0.1:9000”,主机:“192.168.1.19”

php 文件的内容似乎没有什么区别。我一直无法找到 php 错误日志或创建自己的错误日志。我在/etc/php/php.ini 中添加了以下内容:

error_log = /var/log/php_error.log

我使文件世界可写,但那里什么也没有。我在/etc/nginx/nginx.conf 中添加了以下内容:

location ~ \.php$ {
            root           /usr/share/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi.conf;
        }

取消注释注释行不会改变任何内容。注释未注释的行会将显示的浏览器页面从错误页面更改为未找到文件页面。

任何帮助将不胜感激。提前致谢。

【问题讨论】:

  • 你在运行 PHP PHP-fpm吗?
  • php-fpm 已安装且服务处于活动状态。我安装了 php 包。我是在不需要启用或启动 php 的假设下操作的

标签: php linux nginx fastcgi archlinux


【解决方案1】:

尝试将您的配置文件更改为:

location ~ \.php$ {
    root           /usr/share/nginx/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi.conf;
}

【讨论】:

  • 谢谢,但在进行了建议的修改后,我无法重新启动 nginx。我收到以下消息: nginx: [emerg] unknown "documant_root" variable
  • 我猜斜线不见了 (/) $document_root/$fastcgi_script_name;或者如果不需要,您可以删除该行。
【解决方案2】:

我想通了。我必须取消注释 php-fpm.conf 文件中的一行,才能让 fastcgi 在正确的端口上侦听。

【讨论】:

  • 这个文件的路径?
  • 你取消了哪一行的注释?
猜你喜欢
  • 2021-09-25
  • 2014-08-28
  • 2014-05-10
  • 2018-07-28
  • 2017-03-23
  • 2017-03-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多