限制user_agent

11.29 限制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>

OR:匹配的意思。user_agent匹配当前行或者下面一行。如果不加OR就是并且
NC:表示忽略大小写。因为有些浏览器首字符会大写。
F:就是直接Forbidden
因为curl是没有user_agent(上一次访问的地址)
curl -A "123123" 指定user_agent //自定义user_agent
curl -A "lsx lsx" -x192.168.211.150:80 discuz2.com/lsx/1.php -I //user_agent生效
cat /usr/local/apache2.4/logs/discuz2.com-access_log
192.168.211.150 - - [ +0800] "HEAD HTTP://discuz2.com/lsx/1.php HTTP/1.1" 200 - "-" "lsx lsx"

关于curl:
-A :指定user_agent
-e:指定Referer
-x:相当于省略hosts
-I:查看状态码

11.30 PHP相关配置

查看php配置文件位置

/usr/local/php/bin/php -i|grep -i "loaded configuration file"

Loaded Configuration File => /usr/local/php/etc/php.ini

没有php.ini 那么就需要复制模板过来

cd /usr/local/src/php-5.6.30/
cp php.ini-development /usr/local/php/etc/php.ini

编辑php配置文件

vim /usr/local/php/etc/php.ini

禁止危险函数

vim /usr/local/php/etc/php.ini

搜索disable_functions
在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

预览

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

生效配置

/usr/local/apache2.4/bin/apachectl -t
/usr/local/apache2.4/bin/apachectl graceful

效果:

禁用函数后,这些函数就无法被调用,例如phpinfo作用是显示php的配置,而禁用后使用网页无法显示出来;

定义时区

搜索date.timezone
修改date.timezone =为
date.timezone = Asia/Shanghai

关闭错误信息显示

搜索display_errors
将display_errors = On改为
display_errors = Off

定义错误日志

搜索error_log =
修改error_log = 目录为
error_log = /tmp/php_errors.log

定义错误日志级别

搜索error_reporting =
在error_reporting = E_ALL 修改为
error_reporting = E_ALL & ~E_NOTICE

open_basedir参数设定

open_basedir的作用是限制php在指定的目录里活动
vim /usr/local/php/etc/php.ini
搜索error_log =修改为指定目录
open_basedir = /data/wwwroot/111.com:/tmp

推荐在虚拟配置中设置
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
针对网站站点增加代码
php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"

11.32 PHP扩展模块安装

1. cd /usr/local/src/

2. 下载redis  wget https://codeload.github.com/phpredis/phpredis/zip/develop

3. mv develop phpredis-develop.zip     //改名

4. unzip phpredis-develop.zip    //解压文件

5. /usr/local/php7/bin/phpize    //生成conf文件

6. ./configure --with-php-config=/usr/local/php7/bin/php-config    

7. make   

8. make  install

redis.so 存放目录

9. /usr/local/php7/bin/php -i |grep -i extension_dir    //查看扩展模块目录

10.  extension=redis.so     //配置文件添加

猜你喜欢

转载自my.oschina.net/u/3803395/blog/1812402