Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> 電腦軟件教程 >> 服務器技術 >> 關於服務器 >> nginx+php使用open

nginx+php使用open

日期:2017/2/8 10:12:05      編輯:關於服務器
以下三種設置方法均需要PHP版本為5.3或者以上。

方法1)在Nginx配置文件中加入
fastcgi_param  PHP_VALUE  "open_basedir=$document_root:/tmp/:/proc/"; 通常nginx的站點配置文件裡用了include fastcgi.conf;,這樣的,把這行加在fastcgi.conf裡就OK了。
如果某個站點需要單獨設置額外的目錄,把上面的代碼寫在include fastcgi.conf;這行下面就OK了,會把fastcgi.conf中的設置覆蓋掉。
這種方式的設置需要重啟nginx後生效。

方法2)在php.ini中加入:
[HOST=www.45it.com] open_basedir=/home/www/www.45it.com:/tmp/:/proc/ [PATH=/home/www/www.45it.com] open_basedir=/home/www/www.45it.com:/tmp/:/proc/ 這種方式的設置需要重啟php-fpm後生效。

方法3)在網站根目錄下創建.user.ini並寫入:
open_basedir=/home/www/www.45it.com:/tmp/:/proc/ 這種方式不需要重啟nginx或php-fpm服務。安全起見應當取消掉.user.ini文件的寫權限。
關於.user.ini文件的詳細說明:
http://php.net/manual/zh/configuration.file.per-user.php

設置open_basedir的同時最好禁止下執行命令的函數,比如:
shell_exec('ls /etc')仍然查看到/etc目錄的文件列表
shell_exec('cat /etc/passwd')仍可查看到/etc/passwd文件的內容

建議禁止的函數如下:
disable_functions = pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority, eval, popen, passthru, exec, system, shell_exec, proc_open, proc_get_status, chroot, chgrp, chown, ini_alter, ini_restore, dl, pfsockopen, openlog, syslog, readlink, symlink, popepassthru, stream_socket_server, fsocket, chdir
Copyright © Windows教程網 All Rights Reserved