在 Nginx 中将 HTML 文件作为 PHP [英] HTML files as PHP in Nginx

查看:26
本文介绍了在 Nginx 中将 HTML 文件作为 PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于使用 PHP 作为 apache 模块的 Web 服务器:

For web servers using PHP as apache module:

AddType application/x-httpd-php .html .htm

对于将 PHP 作为 CGI 运行的 Web 服务器:

For web servers running PHP as CGI:

AddHandler application/x-httpd-php .html .htm 

我有一个 Nginx 服务器,我想将 .js 文件和 .htm 文件作为 PHP 运行,因此我将在其中包含完整的 PHP 代码.有人知道如何配置 Nginx 来做到这一点吗?

I have an Nginx server and I want to run .js files and and .htm files as PHP, so I will have full PHP code inside them. Anyone know how to configure the Nginx to do this?

推荐答案

.htm、.html 文件示例

Example for .htm, .html files

  location ~ .htm$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.htm;
            include        fastcgi.conf;
  }

.js 文件示例

location ~ .js$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

如果需要,只需更改扩展名和端口设置

just change the extension and port settings if needed

这篇关于在 Nginx 中将 HTML 文件作为 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆