Hello!
2013/1/30 shiano:
> Hi,章老师,遇到一个问题在网上没找到答案,只好向您求助这个问题:
>
>
> location ~ \.php$ {
>
> if ( $request_filename = 'hello.php' ) {
> access_log /opt/logs/${server_name}_access.log;
> }
>
> try_files $uri =404;
> include fastcgi.conf;
> }
>
> 我想针对"hello.php"这个请求开启访问日志(全局访问日志是关闭的),但是不成功,不知道问题出在哪里,希望您百忙之中给予指点,谢谢!
>
如果我是你,我会先用 echo 指令打印出 $request_filename 变量的值:
location ~ \.php$ {
echo $request_filename;
}
访问 /hello.php 时在我这里得到的输出是
$ curl localhost:8080/hello.php
/var/www/html/hello.php
我们看到输出的是绝对路径,而不是相对路径。
$request_filename 变量的文档也指出它的值是路径而不是单纯的文件名:
http://wiki.nginx.org/HttpCoreModule#.24request_filename
所以你的 if 条件永远不会成立。
最简单的做法是使用 $uri 变量:
if ($uri = /hello.php) {
...
}
或者在 if 条件里使用正则匹配。
当然,还有一种更干净的做法是为 hello.php 使用单独的 location. 毕竟“if 是邪恶的”:
http://wiki.nginx.org/IfIsEvil
同时抄送给 openresty 中文邮件列表:http://openresty.org/#Community 也希望你能在那里交流这样的问题。谢谢合作。
Best regards,
-agentzh