禁止解析PHP、限制user_agent、php相关配置

11.28 限定某个目录禁止解析php

  1. 核心配置文件内容
    <Directory /data/wwwroot/www.123.com/upload>
        php_admin_flag engine off
    </Directory>
  1. curl测试时直接返回了php源代码,并未解析
  2. 可以写的目录,99%不需要解析php,静态文件所存放的目录,不允许存放php。

11.29 限制user_agent

  1. user_agent可以理解为浏览器标识
  2. 核心配置文件内容
   <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_USER_AGENT}  .*curl.* [NC,OR]
        RewriteCond %{HTTP_USER_AGENT}  .*baidu.com.* [NC]
        RewriteRule  .*  -  [F]
    </IfModule>//NC 忽略大小写,F为fobidden的意思
  1. curl -A "123123" -x127.0.0.1:80 'http://111.com/123.hph' -A 指定user_agent
    -e 指定referer 必须以“http://”开头
    -x 省略hosts -I 仅仅查看状态骂

11.30/11.31 php相关配置

  1. 查看php配置文件位置 /usr/local/php/bin/php -i|grep -i "loaded configuration file" 在根目录下创建phpinfo(),如下:
<?php
    phoinfo();

通过浏览器查看phpifo;找到路径,找到源码包# cd /usr/local/src/php-7.1.6/
# cp php.ini-development /usr/local/php7/etc/php.ini
# /usr/local/apache2.4/bin/apachectl graceful此时在打开浏览器,查看Loaded Configuration Files的路径

  1. date.timezone //定义时区,Asia/Shanghai
  2. 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 //危险的函数,
  3. display on或off,打开或者关闭错误提示
  4. error_log//定义log路径, log_errors//是否打开错误日志, display_errors, error_reporting//定义日志的级别,默认为E_all,生产环境上使用E_ALL & ~E_NOTICE
  5. open_basedir =/data/wwwroot/111.com:/tmp //php.ini是针对所有站点的,可以在apache的配置文件中做配置,如下: php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"

扩展

  1. apache开启压缩 http://www.aminglinux.com/bbs/thread-5528-1-1.html

  2. apache2.2到2.4配置文件变更 http://www.aminglinux.com/bbs/thread-7292-1-1.html

  3. apache options参数 http://www.aminglinux.com/bbs/thread-1051-1-1.html

  4. apache禁止trace或track防止xss http://www.aminglinux.com/bbs/thread-1045-1-1.html

  5. apache 配置https 支持ssl http://www.aminglinux.com/bbs/thread-1029-1-1.html

猜你喜欢

转载自my.oschina.net/u/3803446/blog/1823511