11.28 限定某个目录禁止解析php
核心配置文件内容
<Directory /data/wwwroot/110.com/upload>
php_admin_flag engine off
</Directory>
curl测试时直接返回了php源代码,并未解析
加一层 FilesMatch 的限制更好, 如果不加, 则会访问到原代码
11.29 限制user_agent
为了防止cc攻击
user_agent可以理解为浏览器标识
核心配置文件内容
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC]
RewriteRule .* - [F]
</IfModule>
F Forbidden的意思
NC 忽略大小写, OR 或者 , 匹配1or2
curl -A "123123" 指定user_agent
cul 常用选项:
-A 指定 user_agent
-x 相当于省略了hosts
-I 只返回状态码, 不返回内容
-e 指定 referer , 必须 http:// 开头 //从网页1访问到网页2, 网页2的referer就是"网页1的地址"
11.30/11.31 php相关配置
查看php配置文件位置
此方法不是很准确, 最正确的方法是去你的网站底下创建一个phpinfo的php文件, 通过php文件查看
/usr/local/php7/bin/php -i|grep -i "loaded configuration file"
php.ini 常用配置
date.timezone=Asia/Shanghai
禁用危险函数, 搜索disable_functions , phpinfo 自己加上 disable_functions=eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo
display_errors=off //是否在页面上显示错误 如果否, 需定义log_errors
log_errors=on //错误日志是否开启 如果是, 则需定义 log_errors 和 error_log , error_reporting
error_log = /tmp/php_errors.log //定义错误日志的路径
error_reporting=E_ALL & ~E_NOTICE //错误日志记录的级别,
如果程序员在php代码中定义了错误日志不输出, 则也不会输出错误日志
定义错误日志完成后要用: /usr/local/apache2.4/bin/apachectl graceful ,然后会生成错误日志文件 /tmp/php_errors.log
保险的话也可以自己先创建错误日志文件并设置权限:
touch /tmp/php_errors.log
chmod 666 /tmp/php_errors.log
日志是以deamon进程的身份去进行的, 有时候定义了一个错误日志, 但日志始终没有生成, 要检查定义了错误日志的所在目录有没有写权限,而且写文件人它是deamon