坚信科学,分享技术

Tag Archives: php

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

跨系统共享键盘鼠标利器分享:synergy

是这样的张总, ?在家里的电脑上按了CTRL+C,然后在公司的电脑上再按CTRL+V是。。。肯定不行的。即使同一篇文章也不行。不不,多贵的电脑都不行。 --题记 端午归来,特此总结,实现上述难题,靠一利器:synergy 此利器可打通mac\linux\windows任意两者的联系,使两个系统共享鼠标和键盘。下面以ubuntu 10.04与盗版windows XP为例。 首先,在ubuntu下面,建立服务端。 #sudo apt-get install synergy quicksynergy #quicksynergy 启动后如图所示: 只需要填写上下左右中的某一个位置修改成另一台机器的机器名,点击执行,常驻运行即可。 然后,在windows下面,安装客户端。 Synergy 1.3 Client 安装运行后如图: 输入Ubuntu机器的ip地址,点Start即可连上两机。 连上之后,可以撤掉在你办公桌面上的一个键盘,鼠标移动到哪个桌面上,键盘针对哪个系统输入,非常好用,还支持复制粘贴,对上班时候用两台电脑的同学非常适用。

Continue reading

Posted in linux | Tagged , | 3 Comments

ubuntu 10.04 LTS版本下的Empathy MSN群聊显示昵称方法

1.关系普及 Empathy是个托,python-papyon是个python实现的msn库,telepathy-butterfly是个完成msn功能的python客户端。 2.修改办法 sudo vim /usr/share/pyshared/papyon/conversation.py 查找 if message_type == 这个字符串 找到内容为: if message_type == 'text/plain': msg = ConversationMessage(unicode(message.body, message_encoding), TextFormat.parse(message_formatting), self.__last_received_msn_objects) try: display_name = message.get_header('P4-Context') 将if判断后try之前中间定义msg这一堆内容修改为如下: try: msg = ConversationMessage(unicode("["+message.get_header('P4-Context')+"]"+message.body, message_encoding), TextFormat.parse(message_formatt

Continue reading

Posted in linux | Tagged , | 6 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
Page 1 of 512345