【SOS】nginx无法解析php文件?

已经在服务器上装了nginx和php,php-fpm(监听9000端口)
可以正常显示html,但是每当输入url打开一个php时,无法正常解析,导致变成下载模式

nginx.conf如下
图片描述

现在打开php直接变成404...Orz

干脆贴出来吧,估计是这一段的问题,搞了好久都没进展....

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
}

阅读 9k
4 个回答

这样写试一下 用nginx -t命令检查你的nginx配置文件是否有错误
location /index.php {

    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;

}

我以前也有过,当时是centos6,后来换成7了。
之后绑定好域名就好了

还能显示nginx的画面
问题是我用域名安装源码怎么就显示404
用ip安装弹出php文件的下载,php我也运行了啊。
网站默认主目录我也已经定位到www.38934.tech上面了。
苦恼啊!
2016-10-26 09:33:34
管理员
请您确保以下3个设置:

  1. 域名解析到服务器IP

  2. Nginx网站管理里有配置这个域名

  3. 修改完配置后有重载或重启Nginx
    目前已为你修正配置。

第一步 nginx.conf的配置

location / {
        if (!-e $request_filename) {
             rewrite  ^/(.*)$  /index.php/$1  last;
             break;
        }
    }

    location ~ ^/s-([0-9a-z]+)-(.*) {
        rewrite ^/s-([0-9a-z]+)-(.*) /shtmls/$1/$2 last;
        break;
    }

    location ~ .+\.php($|/) {
        set $script    $uri;
        set $path_info  "/";
        if ($uri ~ "^(.+\.php)(/.+)") {
              set $script     $1;
              set $path_info  $2;
        }

        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_FILENAME  $document_root/$script;
        fastcgi_param SCRIPT_NAME $script;

    }

第二步 sudo vim /etc/php5/fpm/pool.d/www.conf
将 ;listen = /var/run/php5-fpm.sock
改成 listen = 127.0.0.1:9000

你的代码直接放在/root里么?你改过之后的完成配置也发一下吧。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题