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

核心配置文件内容 <Directory /data/wwwroot/www.123.com/upload> php_admin_flag engine off </Directory> curl测试时直接返回了php源代码,并未解析

curl -x127.0.0.1:80 'http://123.com/upload/123.php'

11.29 限制user_agent

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> curl -A "123123" 指定user_agent

[root@martinlinux001 upload]# curl -x127.0.0.1:80 'http://123.com' <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> Forbidden <p>You don't have permission to access / on this server.<br /> </p> </body></html> [root@martinlinux001 upload]# curl -x127.0.0.1:80 'http://123.com/upload/123.php' <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> Forbidden <p>You don't have permission to access /upload/123.php on this server.<br /> </p> </body></html>

11.30/11.31 php相关配置

查看PHP配置文件:

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

设定时区 date.timezone 一些功能选项: “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 ” 以上功能选项可以通过“disable_function”来限制,以达到提高网站安全性的目的:

disable_function= 日志相关 display_errors=On/Off :设定是否显示错误原因,需要注意的是,此处设置为off(防止用户看到)后必须设置错误日志,设定保存路径,和错误日志级别,否则将无法查找错误原因 。

log_errors=On/Off 开启/关闭错误日志

“error_log=/tmp/” 设定错误日志的保存路径。如果定义好路径后无法生产日志,此时需要检查日志文件所在目录是否有写(w)权限

“error_reporting =” 设定错误日志级别,级别有:E_ ALL 、~E_ NOTICE 、~E_ STRICT 、~E_DEPRECATED(可以自由组合)。生产环境使用:E_ ALL & ~E_ NOTICE就可以。

官方说明:

E_ALL (Show all errors, warnings and notices including coding standards.) E_ALL & ~E_NOTICE (Show all errors, except for notices) E_ALL & ~E_NOTICE & ~E_STRICT (Show all errors, except for notices and coding standards warnings.) E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (Show only errors) 安全参数“open_basedir” 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.
译:如果设置了open_basedir选项,将会把所有关于文件的操作限制在指定目录及其子目录。 将该指令设定在每个目录或者虚拟主机web服务器配置文件中非常重要。 说明: php.ini文件中的内容是针对所有虚拟主机进行的配置。

问题: 一台服务器运行着不止一台虚拟主机,所以在该文件下设置该选项并不合适。那么,该如何设定该配置呢?

办法: 分别在每个虚拟主机的配置文件进行相关设置。

[root@martinlinux 123.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf php_admin_value open_basedir "/data/wwwroot/123.com:/tmp/" 说明: “php_admin_value”可以定义php.ini中的参数。使用该办法分别在每个虚拟主机设定相关的“open_basedir”即可! 在此开放“/tmp/”目录是为了使临时文件能正常写入。