php's .user.ini 与 nginx 和子目录 [英] php's .user.ini with nginx and subdirectory

查看:77
本文介绍了php's .user.ini 与 nginx 和子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 nginx 1.2.2 和 PHP 5.4.4.我已经将 PHP 配置为以 FastCGI 运行的 nginx.

I have installed nginx 1.2.2 and PHP 5.4.4. I have configured PHP with nginx running as FastCGI.

nginx 配置片段:

nginx config snippet:

location ~ \.php$ {
    root           E:/Websites/localhost;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  E:/Websites/localhost/$fastcgi_script_name;
    include        fastcgi_params;
}

我在同一系统上运行了许多本地虚拟站点.为了自定义每个要求,我在每个站点根文件夹中创建了 .user.ini 文件,根据 PHP 文档,该文件也应适用于子文件夹.

I have a number of local virtual sites running on same system. To customize each ones requirements I have created .user.ini file in each sites root folder which as per the PHP documentation should be applicable on sub folders also.

请注意,这是一个开发环境而不是实时环境.所以我可以灵活地定制很多东西.

Please note this is a development environment and not live. So I have flexibility to customize a number of things.

当我从浏览器访问任何站点时,它工作正常,除非我不深入到某个子文件夹.似乎 .user.ini 在子目录中不起作用 - 至少在我的配置中是这样.

When I access any site from the browser it works fine unless I do not dive into some sub folder. It seems that .user.ini does not work in sub directories - at least in my configuration.

根据 PHP 文档(http://www.php.net/manual/en/configuration.file.per-user.php):

As per PHP document (http://www.php.net/manual/en/configuration.file.per-user.php):

除了主要的 php.ini 文件,PHP 还会扫描每个文件中的 INI 文件目录,从请求的 PHP 文件的目录开始,以及一直到当前文档根目录

In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root

求救

有没有人在 nginx 下配置过 .user.ini - 请求你帮我.

SOS

Has anyone configured .user.ini under nginx - request you to please help me out.

注意:有人在 2009 年报告了一个错误:https://bugs.php.net/bug.php?id=50374

Note: Someone reported a bug in 2009: https://bugs.php.net/bug.php?id=50374

PHPInfo() 说(在根文件夹和子文件夹中):
* 服务器 API:CGI/FastCGI
* user_ini.filename: .user.ini(本地和主)

PHPInfo() says (in root as well as in sub folders):
* Server API: CGI/FastCGI
* user_ini.filename: .user.ini (local as well as master)

php_sapi_name() 说 cgi-fcgi

php_sapi_name() says cgi-fcgi

这些值存在于根文件夹和子目录的 phpinfo() 中.所以PHPInfo()没有区别.

These values are present in phpinfo() from root folder and sub directories. So there is no difference in PHPInfo().

进一步确认它以 CGI/FastCGI 运行的是根文件夹正在从 .user.ini 中获取配置,而不是从子文件夹中获取配置.

Further confirmation that it is running as CGI/FastCGI is that root folder is taking configurations from .user.ini but not sub folders.

// .user.ini
auto_prepend_file = "E:\Websites\localhost\user.ini.php"

// user.ini.php
<?php
printf('Hi from: %s', __FILE__);
?>

这实际上可能是一个错误,但是有人以这种方式使用 nginx 配置 PHP 并且没有遇到问题.在这种情况下,请求共享版本号和平台.

This may actually be a bug but has anyone configured PHP with nginx in this way and did not faced the problem. Requesting to please share version numbers and platform in this case.

推荐答案

您只是部分引用了您链接到的 PHP 文档.它还说这些文件仅由 CGI/FastCGI SAPI 处理.

You only partially quoted the PHP docs you linked to. It also says These files are processed only by the CGI/FastCGI SAPI.

我怀疑您使用的不是 CGI/FastCGI SAPI,而是其他一些 SAPI ……也许是 PHP-FPM SAPI?

I suspect you are not using the CGI/FastCGI SAPI but some other SAPI ... the PHP-FPM SAPI perhaps?

您可能已经从上文中了解到,运行 FastCGI 并不等同于使用 CGI/FastCGI SAPI.您还可以使用 PHP-FPM 等其他 SAPI 运行 FastCGI.

As you may have figured from the above, running FastCGI is not equivalent to using the CGI/FastCGI SAPI. You can also run FastCGI using other SAPIs such as PHP-FPM.

顺便说一句 SAPI = 服务器 API.您可以在 phpinfo 文件中查找您的.

BTW SAPI = Server API. You can look for yours in a phpinfo file.

这篇关于php&amp;#39;s .user.ini 与 nginx 和子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆