[英]How to execute PHP on Specific HTML Files on NGINX
我在我的一些 HTML 文件中执行 PHP 代码,但由于我只想对某些文件执行此操作,我想仅为特定文件创建.htaccess
规则。
我当前的配置工作正常,但我所有的 html 文件,甚至 static 文件都通过 PHP 引擎解释;
# handle .php
location ~ \.(php|html|htm)$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
include nginxconfig.io/php_fastcgi.conf;
}
我到目前为止尝试的是.htaccess
文件,但看起来它只适用于 Apache;
<Files mypage.html>
AddType application/x-httpd-php .html
</Files>
我应该为每个我想使用 PHP 的 html 文件创建location
吗?
使用精确匹配:
# add another location:
location = /mypage.html {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
include nginxconfig.io/php_fastcgi.conf;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.