Nginx 设置 PHP_VALUE 的灵异问题

之前通过Apache里设置auto_prepend_file / auto_append_file 来实现记录页面执行时间,后来切换到Nginx后就没有设置这个了。

搜索一番,Nginx同样支持这种设置的。

配置如下:

fastcgi_param PHP_VALUE "auto_prepend_file=prepend.php";
fastcgi_param PHP_VALUE "auto_append_file=append.php";

配置好后,重新Nginx,查看phpinfo()的输出,发现有时候auto_prepend_file设置为空,如图。
[caption id="attachment_1204" align="alignnone" width="300"]nginx nginx[/caption]

搜索一番后,发现Nginx不支持多条PHP_VALUE的设置。

Quick little post on a problem I had while trying to use XHGui with my Nginx/PHP-FPM setup. I needed to be able to pass the auto_prepend_file and auto_append_file settings to PHP-FPM from Nginx. In apache you can declare multiple php_value settings. However, when I did the same in nginx, it would only reflect the second setting. Turns out you need to set all of your php_value’s in Nginx in a single string, and you separate them by new line characters.

如果有多条,需要将PHP_VALUE的设置合并到一条记录上,以" \n "进行分隔。

重新配置,如下:

fastcgi_param PHP_VALUE "auto_prepend_file=prepend.php \n auto_append_file=append.php";

重启Nginx,查看phpinfo(),配置生效了。

相关资料:
PHP-FPM, Nginx, PHP_VALUE, and Multiple Values

标签: none

仅有一条评论

  1. Apache中.htaccess文件利用的总结与新思路拓展 - 黑客圈

    [...]Nginx 设置 PHP_VALUE 的灵异问题[...]

添加新评论