加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx下载php而不是运行它

发布时间:2020-12-13 21:28:32 所属栏目:Nginx 来源:网络整理
导读:我在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 { wor

我在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;
        }
    }
最佳答案
我只是有这个完全相同的问题.我正在使用Ubuntu 12.04和Linux Mint 14,所以不同的操作系统,但可能有同样的问题.

几个问题可能会发生.首先,您需要安装php5-fpm(FastCGI Process Manager).我试图用我的标准版本的PHP来运行它,但它不工作 – http://www.php.net/manual/en/install.fpm.php

我也安装了Apache,即使没有运行它也必须有一些冲突,因为一旦卸载了Apache,我就可以执行PHP文件了.

我也会看这条线

fastcgi_pass 127.0.0.1:9000;

并考虑将其更改为

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

以下是为RHEL(和其他操作系统)安装Nginx和PHP5-FPM的详细指南

http://www.if-not-true-then-false.com/2011/install-nginx-php-fpm-on-fedora-centos-red-hat-rhel/

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读