Windows下nginx + tomcat 配置

写了一个 webservice 服务,给其他系统测试使用,如果直接在eclipse里启动,自己编写代码时,就会影响别人使用,于是搭了一个nginx供其他开发人员使用。

网上大部分教程人都有这个说明:

Tomcat服务器作为一个Web服务器,其并发数在300-500之间,如果有超过500的并发数便会出现Tomcat不能响应新的请求的情况,严重影响网站的运行。另外,在访问量大的情况下,Tomcat的线程数会不断增加。由于Tomcat自身对内存的占用有控制,当对内存的占用达到最大值时便会出现内存溢出,对网站的访问严重超时等现象,这时便需要重新启动Tomcat以释放占用的内存,这样做便会阻断网站运行。
所以对Tomcat做负载均衡便很有必要。目前可以和Tomcat做负载均衡的主流服务器是Apache,但是Nginx由于功能多、配置简单等优点逐渐成为很多负载均衡服务器的首选。Nginx的并发数可达到50000,所以理论上可以和Tomcat以1:100的比例来配置,这样便可以很好的解决网站并发瓶颈问题。而且Nginx、apache是基于http反向代理方式,位于ISO模型的第七层应用层。直白些就是TCP
UDP 和http协议的区别,Nginx不能为基于TCP协议的应用提供负载均衡。

但是官网上并有看到这个说明,实际上并发数量还是和机器性能及其他配置有关系的,不能一概而论。有兴趣的可以仔细去官网看下。
http://tomcat.apache.org/tomcat-7.0-doc/config/http.html

maxThreads 的官网说明
The maximum number of request processing threads to be
created by this Connector, which therefore determines the maximum
number of simultaneous requests that can be handled. If not specified,
this attribute is set to 200. If an executor is associated with this
connector, this attribute is ignored as the connector will execute
tasks using the executor rather than an internal thread pool.

一、 下载nginx
本人下载时最新版为 nginx/Windows-1.11.2
http://nginx.org/en/download.html

下载下来是zip,直接解压 nginx.exe即可使用

二、下载tomcat
本人电脑装的是java 1.7,所以使用tomcat 7
http://tomcat.apache.org/download-70.cgi

三、解压tomcat
解压tomcat后,复制一份,这里称为tomcat1,tomcat2
修改一下tomcat/conf/server.xml 里端口,不与现有端口冲突即可
这里假设tomcat1 为8081,tomcat2为8082
测试localhost:8081 localhost:8082 可正常访问即可

四、配置nginx
Nginx根目录下的/conf目录下 nginx.conf

  1. 在#gzip on;后面加入下面配置:
upstream localhost {
    server localhost:8081 weight=5;
    server localhost:8082 weight=5;
    ip_hash;
}
  1. 修改location配置
    location / {
    root html;
    index index.html index.htm;
    }
    改为:

location / {
root html;
index index.html index.htm;
proxy_pass http://localhost;
proxy_redirect off;
proxy_set_header Host host;proxysetheaderXRealIP remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; }

启动nginx

常用nginx 命令:
停止:nginx -s stop
修改配置使配置生效:nginx -s reload
检查配置:nginx -t

http://my.oschina.net/itsuifeng/blog/101911
http://my.oschina.net/psuyun/blog/113694
http://blog.csdn.net/qysh123/article/details/11678903

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值