首頁  >  文章  >  後端開發  >  關於think PHP部署nginx 配置

關於think PHP部署nginx 配置

不言
不言原創
2018-04-27 11:26:492690瀏覽

這篇文章主要介紹了關於think PHP部署nginx 配置,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下

第一個問題:
Warning: require(): open_basedir restriction in effect. File(/mnt/wwwroot/admincc/thinkphp/start.php) is not within the allowed path(s): (/mnt/wwwroot/admincc/public/:/tmp/:/proc/) in /mnt/wwwroot/admincc/public/index.php on line 17Warning: require(/mnt/wwwroot/admincc/thinkphp/start.php): failed to open stream: Operation not permitted in /mnt/wwwroot/admincc/public/index.php on line 17Fatal error: require(): Failed opening required '/mnt/wwwroot/admincc/public/../thinkphp/start.php' (include_path='.:/usr/local/php/lib/php') in /mnt/wwwroot/admincc/public/index.php on line 17

這個是開啟php錯誤提示後顯示的錯誤訊息(如果不開啟提示,瀏覽器只會顯示500錯誤,不便於排查。)

解決方法:

#出現這種錯誤主要受fastcgi.conf中open_basedir參數控制,在我的設定檔中,這個參數的預設值是這樣的:

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";

open_basedir參數的作用就是將php能開啟的檔案限制在特定的目錄樹中,預設的$document_root是nginx.conf中配置的/home/wwwroot/default目錄,而我專案的目錄是在/mnt/wwwroot/admincc/public下,由於專案目錄沒有包含在open_basedir中,因此會報如上的錯,解決方法也就很簡單了,將專案家目錄加入即可。

fastcgi_param PHP_ADMIN_VALUE "open_basedir=/mnt/wwwroot:$document_root/:/tmp/:/proc/";

PS:還有一個解決方法是直接把這個參數註解掉。

第二個問題:

錯誤提示:

scandir() has been disabled for security reasons

錯誤提示是說scandir函數因為安全性原因被停用了。

解決方法:

沒錯,就像它提示的這個函數預設在php.ini是停用的。

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

很明顯,scandir被禁用了,解決方法也簡單,把scandir刪掉,重啟php-fpm就好。

service php-fpm restart
第三个问题:

访问报404错误。

解决办法:

这个的原因在于nginx的配置有问题,在vhost/admincc.conf(站点虚拟主机的配置文件)中添加如下配置即可:

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

由于ThinkPHP的入口文件是index.php,所以要重写下url。
保存配置,记得重启nginx。

相关推荐:

thinkphp部署到万网云服务器上报连接不上mysql

以上是關於think PHP部署nginx 配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn