【发布时间】:2021-03-16 03:17:38
【问题描述】:
我在这方面找到了一些线索,但我找到的解决方案不起作用。我试图让我的 NGINX 服务器在将 html 文件发送到浏览器进行处理之前解释 html 文件中的 php。这是我的服务器括号内的一些代码 - 在我唯一启用站点的目录文件中,“默认:”
location ~ \.(php|html|htm)$ {
include snippets/fastcgi-php.conf;
root html;
fastcgi_index index.php;
# With php-fpm (or other unix sockets):
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
include fastcgi_params;
# With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
具体来说,我希望 (php|hmtl|htm) 的部分成为解决方案。但是,我的 .html 文件中的 php 仍然被注释掉并且没有被处理。
不确定 security.limit_extensions 参数在哪里?这是我在 sn-ps 文件夹中的 fastcgi-php.conf:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
感谢您的任何想法。
【问题讨论】:
-
html文件的扩展名是php。
-
显然是最简单的解决方案。环境阻止我这样做。因此问题。
-
您可以将您的正则表达式缩短为
location ~ \.(php|html?)$ { ... }