[英]How to execute PHP on Specific HTML Files on NGINX
I'm executing PHP code inside some my HTML files, but since I only want to do this on certain files, I want to create .htaccess
rules for specific files only.我在我的一些 HTML 文件中执行 PHP 代码,但由于我只想对某些文件执行此操作,我想仅为特定文件创建
.htaccess
规则。
My current config works fine but it all my html files, even static ones interpreted through PHP engine;我当前的配置工作正常,但我所有的 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;
}
What I tried to far is on .htaccess
file but looks like it only works with Apache;我到目前为止尝试的是
.htaccess
文件,但看起来它只适用于 Apache;
<Files mypage.html>
AddType application/x-httpd-php .html
</Files>
Should I create location
for each html file I should want to work with PHP?我应该为每个我想使用 PHP 的 html 文件创建
location
吗?
Use exact matching:使用精确匹配:
# 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.