分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

11.28 限定某个目录禁止解析php 11.29 限制user_agent 11.30/11.31

发布时间:2023-09-06 01:45责任编辑:傅花花关键词:暂无标签
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>
<h1>Forbidden</h1>
<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>
<h1>Forbidden</h1>
<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)权限

“errorreporting =” 设定错误日志级别,级别有:E ALL 、~E NOTICE 、~E STRICT 、~EDEPRECATED(可以自由组合)。生产环境使用: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/”目录是为了使临时文件能正常写入。

11.28 限定某个目录禁止解析php 11.29 限制user_agent 11.30/11.31

原文地址:http://blog.51cto.com/12058686/2084515

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved