- 论坛徽章:
- 0
|
试试nginx+fastcgi+php,代理resin。
resin本身支持集群模式,容许通过多进程方式启动多个端口,同时通过自己的代理机制负载均衡多个端口,不过他自己的负载均衡需要专业版才支持,这个工作可以由nginx来操作。
resin多端口详见:http://caucho.com/resin/doc/resin-clustering.xtp
配置方法是在resin.conf内的app-tire中增加集群ip和端口,web-tire就是它自身的负载均衡配置,专业版才可以使。
启动方式:java -jar resin_home/lib/resin.jar -server app-a start
这样端口就启用了,直接访问8081端口可以获得http响应。
nginx代理的配置一般的都是按照扩展名为jsp指向到resin的做法配置,我觉得这样不合理因为Servlet是没扩展名的,php都会使用.php来结尾。由于我不同的业务都有域名,所以域名配置虚拟主机的时候,用/来配置为代理resin,之于php的业务就可以根据扩展名来配置了。配置文件如下,php的配置和普通的fastcgi没区别。由于resin是多端口session是无法共享使用的,resin专业版的做法是依靠cookie粘性来区分用户访问的是哪个端口并保持一致访问这个端口,使用nginx代理就使用ip_hash,根据访问ip来分到同一个端口。
nginx.conf
18 http {
19 include mime.types;
20 default_type application/octet-stream;
21 server_names_hash_bucket_size 512;
22 upstream resinserver {
23 ip_hash;
24 server 127.0.0.1:8081;
25 server 127.0.0.1:8082;
26 server 127.0.0.1:8083;
27 }
........省略.....
}
1 server {
2 listen 80;
3 server_name xxxx.com;
4 index index.html index.jsp;
5 ssi on;
6 root /website/jwww/;
7 location /{
8 proxy_pass http://resinserver;
9 proxy_redirect off;
10 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
11 proxy_set_header X-Real-IP $remote_addr;
12 proxy_set_header Host $http_host;
13 }
14 }
不过按道理来说,由于resin是多进程,3个进程分担请求肯定要比一个进程效率高,但是我经过apacheab做测试 并发50,100,200,300 单进程和多进程+NGINX的速度基本一致,后者还要比单进程的慢几毫秒~~~~没想明白问题。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12909/showart_2090111.html |
|