Nginx中的HTML文件为PHP

The*_*Kid 3 .htaccess nginx addhandler

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

AddType application/x-httpd-php .html .htm
Run Code Online (Sandbox Code Playgroud)

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

AddHandler application/x-httpd-php .html .htm 
Run Code Online (Sandbox Code Playgroud)

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

小智 19

传递给fastcgi并不适合我.经过几个小时的搜索,我在这里找到了解决方案:http: //ffct.cc/solving-nginx-php-fpm-access-denied-issue/

简而言之:

因为PHP版本> 5.3.8,为了使它工作,你应该添加指令到php-fpm.conf:

security.limit_extensions = .php .html .js
Run Code Online (Sandbox Code Playgroud)

识别标志是"拒绝访问".(当注意访问.html.js文件时,请注意它与HTTP错误403不同).


小智 10

简单; 只是改变

location ~ \.php$ {
        root           html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
Run Code Online (Sandbox Code Playgroud)

location ~ \.(php|html|htm)$ {
        root           html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param    SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
Run Code Online (Sandbox Code Playgroud)


Sal*_*ros 4

.htm、.html 文件示例

  location ~ \.htm$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.htm;
            include        fastcgi.conf;
  }
Run Code Online (Sandbox Code Playgroud)

.js 文件示例

location ~ \.js$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
Run Code Online (Sandbox Code Playgroud)

如果需要,只需更改分机和端口设置