Press "Enter" to skip to content

CentOS 6设置防跨站

利用open_basedir将PHP脚本的操作限定在某一个目录内,可以防止跨站攻击。本文基于CentOS 6,PHP 5.5.5版本。假设我们有一个网站位于/home/wwwroot/。

$ 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.
;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/    #写入如下一行

$ chmod 644 /home/wwwroot/
$ chown -R root:root /home/wwwroot/
$ chattr +i /home/wwwroot/


Leave a Reply

Your email address will not be published. Required fields are marked *