技術員聯盟提供win764位系統(tǒng)下載,win10,win7,xp,裝機純凈版,64位旗艦版,綠色軟件,免費軟件下載基地!

當前位置:主頁 > 教程 > 服務器類 >

nginx+php使用open_basedir限制站點目錄防止跨站

來源:技術員聯盟┆發(fā)布時間:2018-10-14 12:12┆點擊:

  方法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.3lian.com]

open_basedir=http://www.3lian.com/home/www/www.45it.com:/tmp/:/proc/

[PATH=http://www.3lian.com/home/www/www.45it.com]

open_basedir=http://www.3lian.com/home/www/www.45it.com:/tmp/:/proc/

 

這種方式的設置需要重啟php-fpm后生效。

  方法3)在網站根目錄下創(chuàng)建.user.ini并寫入:

open_basedir=http://www.3lian.com/home/www/www.45it.com:/tmp/:/proc/

 

這種方式不需要重啟nginx或php-fpm服務。安全起見應當取消掉.user.ini文件的寫權限。

  關于.user.ini文件的詳細說明:

  

  設置open_basedir的同時最好禁止下執(zhí)行命令的函數,比如:

  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