坚信科学,分享技术

Tag Archives:

nginx防hashdos模块使用帮助

经过上周一周朋友们帮忙测试和bug fix,nginx_http_hashdos_module已经达到可以线上使用的水平,下面是使用记录。 下载 #wget --no-check-certificate https://github.com/54chen/nginx-http-hashdos-module/zipball/master #mv master nginx_hashdos.zip #unzip nginx_hashdos.zip 编译安装 #tar zxvf nginx-1.0.xx.tar.gz #cd nginx-1.0.xx/ #./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../54chen-nginx-http-hashdos-module-f84d909 #make && make install 配置注意事项 在http段,增加如下: hashdos on; body_max_count 1000; 在各自的location段,要按照业务情况来加: client_body_buffer_size 2m; client_max_body_size 2m; …

Continue reading

Posted in linux, 架构研究 | Tagged , | Leave a comment

nginx防hashdos模块释出

2012.1.7 更新 编译的时候推荐使用nginx-1.0以上版本,不要加--with-debug参数编译,(感谢agentzh指出)。 hashdos这个事,严格意义上不是各种语言的错了(不过perl的确处理得很好),但是用nginx来擦屁股要干净些。 借鉴tomcat的作法,实现了下面这个nginx-http-hashdos-module,通过设置hashdos(默认on)的开关和body_max_count(默认值1000),对nginx后面的服务进行安全防护,相比对php或者java进行patch,这或许是最好的办法了。 nginx-http-hashdos-module项目地址 https://github.com/54chen/nginx-http-hashdos-module 如何使用 1.下载zip后保存到一个目录,如~/nginx-http-hashdos-module。 2.cd nginx-1.0.9/ 3.重新编译和安装nginx ./configure --prefix=/opt/soft/nginx --with-pcre --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=/path_to/nginx-http-hashdos-module/ && make && make install 4.配置打开: hashdos on; body_max_count

Continue reading

Posted in WEB相关, 架构研究 | Tagged , | 11 Comments

quercus记录:php使用连接池访问数据库

上周记录了如何用quercus建立混合型项目。 http://www.54chen.com/php-tech/quercus-notes-php-java-mixed-projects.html 这里来说说与数据库的访问,使用jndi得到连接池的好处。 JNDI (Java Naming and Directory Interface)是SUN公司提供的一种标准的Java命名系统接口,JNDI提供统一的客户端API,通过不同的访问提供者接口JNDI SPI的实现,由管理者将JNDI API映射为特定的命名服务和目录系统,使得Java应用程序可以和这些命名服务和目录服务之间进行交互。 正题 在quercus中可以随意使用mysql_connect与mysql_pconnect两个方法来连接数据库。 当在web.xml定义得有database相关的消息时,mysql_connect与mysql_pconnect都会自动忽略里面的参数设置,直接使用web.xml的定义。 添加jndi设置: vim WEB-INF/web.xml <?xml version="1.0" encoding="utf-8"?>   <web-app  xmlns="http://caucho.com/ns/resin">     <description>truth application</description>  

Continue reading

Posted in java, php | Tagged , , | 1 Comment

quercus记录:php和java的混合型项目建立手记

创业公司参与项目的人口众多、背景不一,目前市场上的主流方向为php与java,很多时候java工程师恨铁不成钢,php工程师也无可奈何。于是便有了此文,讲述如何使用quercus创建php java混合型项目。 quercus是什么? quercus是Caucho公司针对php语言的java实现,100%完成了php5的解析。是resin内建支持的功能。同时,因为使用了resin,使得php可以很容易得到连接池、分布式session、负载均衡等功能。使用resin的php项目可以更加安全,不存在很多fastcgi的问题。 性能如何? 官方:用mediawiki与drupal来做实验,要比mod_php快4倍。 有一个编译选项,在resin专业版里支持,可以把php转成java class,得到更高性能。 新建一个java项目混合php项目 web.xml是关键,里面声明了*.php文件的访问都以com.caucho.quercus.servlet.QuercusServlet来执行。 <?xml version="1.0" encoding="UTF-8"?>   <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun

Continue reading

Posted in java, php | Tagged , , | 4 Comments

[nginx]如何在access log中记录post请求的参数

移动互联网行业开发过程中,服务端经常会需要检查是否收到请求,收到什么样的请求,最简单的办法就是看nginx的access log,常见的nginx配置中access log一般都只有GET请求的参数,而POST请求的参数却不行。 http://wiki.nginx.org/NginxHttpCoreModule#.24request_body $request_body This variable(0.7.58+) contains the body of the request. The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass. 正如上文件所示,只需要使用$request_body即可打出post的数据,在现存的server段加上下面的设置即可: log_format access '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" "$http_user_agent" $http_x_forwarded_for'; …

Continue reading

Posted in WEB相关 | Tagged , , | 2 Comments

nginx.conf控制指定的代理ip和ip访问的设置手记

工作中有一次用到利用nginx的配置来让只有公司ip的访问才能打开指定的后台url,于是有了下面的记录。 在nginx中if很弱,http://www.nginxcn.com/doc/standard/httprewrite.html,基本上不能写太复杂的条件或者是嵌套。 因为公司我(54chen)网络的设置,过去打到服务器的ip有可能是几个ip,同时也有可能是代理的ip,所以在if判断的时候,可能有多个条件。 location /administrator { #log_format www_54chen_com '$remote_addr - $remote_user [$time_local] $request ' # '"$status" $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; # access_log /data/www.log www_54chen_com; set $fuck 0; if ($remote_addr = '1.1.1.1'){ set $fuck 1; } if ($remote_addr = …

Continue reading

Posted in linux | Tagged , | 2 Comments

[警示]Nginx + PHP CGI的安全漏洞:fix_pathinfo

如果你正在使用nginx+php,请关注。 表像: 具体的重现过程,用php代码修改后缀名后上传,比如说www.xxx.com/1.jpg,访问的时候用www.xxx.com/1.jpg/xxx.php 这段jpg代码将会被执行!!! http://docs.php.net/manual/zh/ini.core.php cgi.fix_pathinfo "1" PHP_INI_ALL 从 PHP 4.3.0 起可用 请注意:默认为1 解决办法: 1.修改php.ini中的cgi.cgi.fix_pathinfo为0(即使你在php.ini中没有搜到,也要设置,没有搜到表示默认为1) 2.判断文件上传类型时使用严格的判断,至于怎么判断,参见:http://www.54chen.com/php-tech/php-upload-file-types-to-determine-the-complete-program-and-php-nginx-upload-size-and-complete-control-program.html 3.把nginx的判断正则修改为去除/ if ( $fastcgi_script_name ~ \..*\/.*php ) { return 403; } 鸟哥在http://www.laruence.com/2010/05/20/1495.html一文中提及此事。

Continue reading

Posted in php | Tagged , | 3 Comments

从php核心代码看require和include的区别

前言 五一长假归来,休息长时间很有点不习惯,回到北京已经有些不适应了。 见到鸟哥的一文:深入理解PHP之require/include顺序 http://www.laruence.com/2010/05/04/1450.html 忍不住继续再深入了一下下,在此记录一下深入的过程,以供以后查阅。 普及 在php手册中: require() is identical to include() except upon failure it will also produce a fatal E_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which …

Continue reading

Posted in php | Tagged , , | 10 Comments

PHP上传进度条深度解析

随着互联网的发展,越来越多的技术开始注重用户体验,以人为本才是长久之道,于是在上传的时候,大家都不再满足一个单一的“浏览”按钮,纷纷推出了带上传进度条的功能。而作为解释型语言的PHP,如何做到对上传文件的检测,如何实现上传进度条以其背后的原理,54chen将在本文中一步步展开。 一. 实现篇 一般情况,用PHP实现上传进度条就下面两种方法: 1.APC扩展(作者是PHP的创始人,5.2后PHP已经加入APC扩展) 2.PECL扩展模块 uploadprogress 不论是APC还是uploadprogress,都需要编译源码,因为原有的PHP函数根本不可能读取到临时文件夹里的东西。下面来看如何使用以及关键的代码: APC实现方法: 1.安装APC 2.配置php.ini,设置参数 apc.rfc1867=1 3.关键代码: if ($_SERVER['REQUEST_METHOD'] == 'POST') {  //上传请求 $status = apc_fetch('upload_' . $_POST['APC_UPLOAD_PROGRESS']); $status['done'] = 1; echo json_encode($status);  //输出给用户端页面里的ajax调用,相关文档请自己寻找 exit; } elseif (isset($_GET['progress_key'])) {   //读取上传进度 $status = apc_fetch('upload_'.$_GET['progress_key']); …

Continue reading

Posted in php | Tagged , | 2 Comments

五四陈透过PHP看JAVA系列:fsockopen

本系列主要总结PHP与JAVA之间的一些异同,给从PHP学JAVA或者是从JAVA学PHP的同学一点启发,五四陈科学院出品。 第一部分,先看PHP的fsockopen 先来看PHP手册中的定义http://www.54chen.com/p/function.fsockopen.html 看完定义后,来看一段代码,利用PHP去更新squid的缓存: <?php function updateCache($myUrl) { global $vSquidConfig; foreach ( $vSquidConfig ['host'] as $mySquid ) { $myHandle = @fsockopen ( "127.0.0.1", 80, $myErrNo, $myErrStr, 30 ); if ($myHandle) { $myResult = ''; @fputs ( $myHandle, "PURGE " . …

Continue reading

Posted in java, php | Tagged , , | 4 Comments
Page 1 of 3123