Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx下载php而不是运行它_Php_Linux_Nginx_Fastcgi - Fatal编程技术网

Nginx下载php而不是运行它

Nginx下载php而不是运行它,php,linux,nginx,fastcgi,Php,Linux,Nginx,Fastcgi,Iv'e在linux REHL机器上设置Nginx php服务器。 当访问html文件时,一切都进行得很顺利,但是尝试访问php文件时,文件会被下载而不是执行 这是我的nginx.conf: user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } h

Iv'e在linux REHL机器上设置Nginx php服务器。 当访问html文件时,一切都进行得很顺利,但是尝试访问php文件时,文件会被下载而不是执行

这是我的nginx.conf:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}
…这是服务器块:

server {
    listen       80;
    server_name  {mywebsitename};

    #access_log  logs/host.access.log  main;

    location / {
        root   /usr/share/nginx/html/{mywebsitename}/;
    }

    location /ngx_status_2462 {
      stub_status on;
      access_log   off;
      allow all;
    }

    location ~ \.php$ {
#                fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/{mywebsitename}$fastcgi_script_name;
        include fastcgi_params;
        }

        error_page  404              /404.html;

        location = /404.html {
            root   /usr/share/nginx/html;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    }

这可能是因为您发送的mimetype:

default_type  application/octet-stream;

请看:

我刚刚遇到了完全相同的问题。我使用的是Ubuntu12.04和LinuxMint14,它们的操作系统非常不同,但可能有相同的问题

可能会发生一些问题。首先,您需要安装php5 fpm(FastCGI Process Manager)。我试图用我的PHP标准版本运行它,但它不起作用-

我还安装了Apache,即使它没有运行,也一定有一些冲突,因为一旦我卸载了Apache,我就能够执行PHP文件

我也会看看这条线

fastcgi_pass 127.0.0.1:9000;

并考虑将其改为

fastcgi_pass   unix:/var/run/php5-fpm.sock;
以下是针对RHEL(和其他操作系统)安装Nginx和PHP5-FPM的详细指南


您需要将文件a/etc/php-fpm.d/www.conf中的用户改为nginx而不是apache

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
;user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache
group = nginx

当然,重新启动服务php fpm restart和服务nginx restart

注释掉
default\u类型应用程序/octet流

这是一个小问题,您编写了
root/usr/share/nginx/html/{mywebsitename}/
所以我假设
{mywebsitename}
不包含尾随的
/
,所以
{mywebsitename}$fastcgi\u script\u name
应该是
{mywebsitename}/$fastcgi\u script\u name对吗?(加了一条斜线)就是这样。非常感谢!卸载apache2为我修复了它,之后,PHP脚本被执行而不是下载。。。我想知道apache2在某种程度上篡改了MIME类型之类的东西……卸载apache2的另一种选择:当根目录(
/var/www/html
对我来说)对于nginx和apache2都是相同的时,nginx会下载php文件(即使apache没有运行,就像你一样)。但是,将nginx的根目录移动到另一个目录(我在
/var/www/nginx/
创建了一个)会导致nginx正常工作。遇到此问题,但仅针对根URL。花了2-3个小时试图解决这个问题,最终找到了你的答案。如果可以,我会给你所有的选票。