HTML文件作为PHP中的Nginx文件、HTML、Nginx、PHP

2023-09-02 11:25:54 作者:倾国倾城倾死你?

有关使用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 code。任何人都知道如何配置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文件

Example for .js files

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

 
精彩推荐
图片推荐