Nginx和FastCGI下载PHP文件而不是处理它们

问题描述:

我正在Windows 7(64位),PHP 5.4.12和Nginx 1.5.8上运行.

I'm running on Windows 7 (64-bit), with PHP 5.4.12, and Nginx 1.5.8.

我已经阅读了很多有关设置和解决此问题的教程,这是当从本地主机请求PHP文件时,它会将其下载为文件而不显示PHP页面.以下是我的nginx.conf文件:

I have read many tutorials on setting this up, and troubleshooting this issue, which is that when requesting a PHP file from my localhost, it downloads it as a file instead of displaying the PHP page. Below is my nginx.conf file:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen 8081;
        server_name localhost;
        access_log C:/nginx/logs/access.log;
        error_log C:/nginx/logs/error.log;
        root C:/nginx/html;

        fastcgi_param  REDIRECT_STATUS    200;

        location ~ \.php$ {
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
        }
    }

}

我正在通过命令提示符手动运行nginx.exe. 我还尝试过先在单独的命令提示符下手动启动php-cgi.exe,如下所示:

I'm running nginx.exe manually through the command prompt. I've also tried starting php-cgi.exe manually first at a separate command prompt, like so:

C:\php5.4.12\php-cgi.exe -b 127.0.0.1:9000

我请求的php文件在C:/nginx/html中,并且我将其请求为:

The php file I'm requesting is within C:/nginx/html, and I'm requesting it as:

http://localhost:8081/info.php

并下载它.该PHP文件的内容为:

And it downloads it. The contents of this PHP file are:

<?php
phpinfo();
?>

如何使我的PHP脚本在此环境中运行.有人对此有经验吗?

How can I possibly get my PHP scripts to run in this environment. Anyone have experience with this?

尝试将default_type application/octet-stream;更改为default_type text/html; 也许您的php脚本未设置内容MIME类型,而它来自nginx.

Try to change default_type application/octet-stream; to default_type text/html; Maybe your php-script does not set a content MIME type and it goes from nginx.