我的nginx + fastcgi配置下载php文件而不是执行它们

iRy*_*ell 10 fastcgi nginx

我在ubuntu 13.04上全新安装php5-fpm和nginx时使用此配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
            try_files $uri $uri/ /index.html;
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            allow ::1;
            deny all;
    }

    error_page 404 /404.html;

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我的Web浏览器将php视为文本而不是执行结果.我应该在哪里进行故障排除?

Moh*_*ady 7

你的PHP代码是直接显示的,因为它没有被发送到php引擎,这意味着位置块正在匹配并且正在提供php文件,但php文件没有被php块捕获,所以你的问题在php块中.

在那个块中你有2个fastcgi_pass,一个有一个端口(9000)而另一个有一个unix socket,你不能把它们放在一起,但是因为你用fastcgi标记了你的问题,所以我假设你使用的是fastcgi,试着评论这一行

#fastcgi_pass unix:/var/run/php5-fpm.sock;
Run Code Online (Sandbox Code Playgroud)