【发布时间】:2016-08-16 12:03:13
【问题描述】:
我有以下配置:
server {
listen 80 default_server;
access_log /var/www/logs/access.log;
error_log /var/www/logs/error.log error;
root /var/www/web/;
index index.html index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
# HACK: This is temporary to work around renaming dozens of HTML links
location ~ \.htm$ {
root html;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.htm;
include fastcgi_params;
}
# HACK: This is temporary to work around renaming dozens of HTML links
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
我更新了 /etc/php5/fpm/pool.d/www.conf 添加以下行:
security.limit_extensions = .php .html
重新启动 FPM 和 NGINX,但是当我访问 .html 文件时,PHP 未呈现...*.php 文件按预期执行...
我还缺少什么???
【问题讨论】:
-
我尝试将 PHP 注释掉,所以它只是 html,但也没有用?!?
-
旁注:你的正则表达式看起来很奇怪:
.+?。这意味着“至少一个令牌,这是可选的”。使用.+(至少一个)或.*(零个或多个)。在这种特定情况下,您当然应该使用.+,因为任何文件都不应该以.php开头。