nginx正则表达式的'(?U)'是什么意思

时间:2013-03-27 11:14:01

标签: nginx fastcgi

我正在阅读nginx的文档,但我不知道这个'(?U)'正在这个正则表达式中做什么。

http://wiki.nginx.org/HttpFastcgiModule#fastcgi_split_path_info

这是一个例子。脚本show.php接收字符串文章/ 0001作为参数。以下配置将正确处理路径分割:

location ~ ^.+\.php {
  (...)
  fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param PATH_INFO $fastcgi_path_info;
  fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  (...)
}

请求/show.php/article/0001将SCRIPT_FILENAME设置为/path/to/php/show.php,将PATH_INFO设置为/ article / 0001。

这个正则表达式还不够?

fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;

由于

1 个答案:

答案 0 :(得分:6)

?U在正则表达式中是不合适的。默认情况下,正则表达式使用“贪婪”模式。

在这种情况下,需要它。使用贪婪匹配,此后续请求

/show.php/article/0001/another.php/something

将脚本部分设置为

/show.php/article/0001/another.php

这可能会导致意外的安全问题。

[<强>更新

nginx使用pcre正则表达式:http://www.pcre.org/pcre.txt

    (?U)            default ungreedy (lazy)