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

标签 nginx fastcgi

我在 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;
    }
}

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

最佳答案

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

在该 block 中,您有 2 个 fastcgi_pass,一个具有端口 (9000),另一个具有 unix 套接字,您不能同时拥有两者,但由于您已将问题标记为fastcgi 所以我假设你正在使用 fastcgi,尝试评论这一行

#fastcgi_pass unix:/var/run/php5-fpm.sock;

关于nginx - 我的 nginx + fastcgi 配置下载 php 文件而不是执行它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17777774/

相关文章:

node.js - 防止显示我正在使用express/NginX

mysql - 升级到wordpress 3.5.1后出错

php - 为什么我收到错误 : recv() failed (104: Connection reset by peer) while reading response header from upstream during ajax request

django - 使用 IIS 8 + Python 3.4 + Django 1.8 + Windows Server 2012 运行 Fastcgi 时出现错误 0x80070585

web-services - 如何通过nginx平衡tomcat webservice?

php - 如果检测到php fatal error ,如何配置nginx转到静态html页面?

node.js 本身或用于提供静态文件的 nginx 前端?

php - 现在的 C++ CGI

apache - FastCGI超时错误MAMP Pro 4

nginx - 如何安装 php-fpm-5.5 rpm 并同时安装所有依赖项