- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
利用open_basedir将PHP脚本的操作限定在某一个目录内,可以防止跨站攻击。本文基于CentOS 6,PHP 5.5.5版本。假设我们有一个网站位于/home/wwwroot/baidu,com。
$ vim /usr/local/php/etc/php.ini #保证php.ini文件里的相关设定未被修改
; open_basedir, if set, limits all file operations to the defined directory ; and below. This directive makes most sense if used in a per-directory ; or per-virtualhost web server configuration file. This directive is ; *NOT* affected by whether Safe Mode is turned On or Off. ; http://www.landui.com/open-basedir ;open_basedir = #这一项保持默认即可 ...... ; 建议关闭的函数 disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server ...... ; 确保如下项保持默认 ;;;;;;;;;;;;;;;;;;;; ; php.ini Options ; ;;;;;;;;;;;;;;;;;;;; ; Name for user-defined php.ini (.htaccess) files. Default is ".user.ini" ;user_ini.filename = ".user.ini" ; To disable this feature set this option to empty value ;user_ini.filename = ; TTL for user-defined php.ini files (time-to-live) in seconds. Default is 300 seconds (5 minutes) ;user_ini.cache_ttl = 300
$ vim /home/wwwroot/zhukun.net/.user.ini #写入如下一行
open_basedir=/home/wwwroot/zhukun.net:/tmp/:/proc/
#相关安全权限设定
$ chmod 644 /home/wwwroot/baidu,com/.user.ini
$ chown -R root:root /home/wwwroot/baidu,com/.user.ini
$ chattr +i /home/wwwroot/baidu,com/.user.ini
很多人觉得,我设定的open_basedir是否有效?很简单,只要将open_basedir后面的路径改一下,重启一下PHP服务,然后观察网站是否还能正常访问即可。
售前咨询
售后咨询
备案咨询
二维码
TOP