PHP open_basedir函數致使的一個nginx配置問題

項目使用CI框架,從Windows平臺遷移到LNMP平臺上的時候發現打開首頁的時候提示
open_basedir
而後看到這個提示的時候下意識的就去了php.ini配置文件中加了open_basedir=/vagrant/vbee/:/tmp/:/proc/ 重啓後依然不行。php

因而各類GUGO。找到了不少都是關於Apache的。試了不少方法都沒法解決。
好比Apache中相似下面這樣html

<DirectoryMatch "/home/sites/site81/">
    php_admin_value open_basedir "/vagrant/vbee2:/tmp/:/"
</DirectoryMatch>

可是nginx中不太懂配置,因此直接在nginx.conf中的server段中加入了
fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/usr/local/lib/php/:/tmp/;
發現仍是沒有解決。後來去SF.GG上提問一個網友給了提示,說是報錯信息中/mnt/web_site_log/www.vbee.com/目錄須要加入到open_basedir中,這纔想到剛剛上面的那句配置少了/mnt/web_site_log/www.vbee.com/這個目錄。因而後來加入到虛擬主機的配置文件server{}中發現終於OK了。nginx

location ~ [^/]\.php(/|$)
        {
            # comment try_files $uri =404; to enable pathinfo
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_param PHP_ADMIN_VALUE open_basedir=$document_root/:/mnt/web_site_log/www.vbee.com/:/tmp/;
            #include pathinfo.conf;
        }

只是目前還沒太明白這樣配置的原理,有空還真的瞭解瞭解服務器的配置。
參考資料:https://centminmod.com/nginx_configure_xenforo_seo_friendly_urls.htmlweb


2015.12.01更新

php5.3之後能夠經過web根目錄下的.user.ini文件進行open_base的配置,即在網站根目錄下存在.user.ini文件,內容相似以下segmentfault

open_basedir=/vagrant/mongo:/tmp/:/proc/:/mnt/web_site_log/www.abc.com/

不過一些敏感的配置仍是不能使用這個配置,好比disable_functions
參考http://drops.wooyun.org/tips/3424服務器

相關文章
相關標籤/搜索