【SOS】nginx无法解析php文件?
迷茫
迷茫 2017-04-10 17:48:07
[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;
}

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(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;

}

PHP中文网

我以前也有过,当时是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

PHPz

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号