windows下tomcat和nginx负载均衡的简单配置!
2015-11-06 16:44
561 查看
1.首先配置2个tomcat,本机不要制定catalina_home环境变量,如果实验状况为台机器,效果更好(我的测试环境用了2台电脑)
更改其中一个tomcat的conf文件的 <Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" 号和
<Server port="8055" shutdown="SHUTDOWN">,如果conf文件下还有没有被注释的使用端口号的配置,请一并更改。
2.安装nginx,请注意版本。直接解压硬盘目录,我这里是:D:\nginx-1.8.0
3.修改nginx的conf文件夹下nginx.conf文件,如下:
4.进入nginx目录下启动nginx:
nginx -s reload 为重新启动nginx进程
nginx -s stop为关闭nginx进程
nginx -t 命令出现如上图所示表示配置文件无错误
5.访问页面:
192.168.1.109服务器上的首页(页面有些敏感信息,故显示一个小角)
我自己本机去掉(css和改变内容的登陆页面)
不停访问该页面,可发现随机出现以上情况,由此可见,nginx充当反向代理服务器和负载均衡已经实现。
若不理解反向代理等知识,请看我转载的一篇经典文章:正向代理,反向代理和透明代理的原理和区别!
更改其中一个tomcat的conf文件的 <Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" 号和
<Server port="8055" shutdown="SHUTDOWN">,如果conf文件下还有没有被注释的使用端口号的配置,请一并更改。
2.安装nginx,请注意版本。直接解压硬盘目录,我这里是:D:\nginx-1.8.0
3.修改nginx的conf文件夹下nginx.conf文件,如下:
error_log logs/error.log; worker_processes 2; worker_rlimit_nofile 1024; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$gzip_ratio" $request_time $bytes_sent $request_length'; access_log logs/access.log main; include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; #gzip on; upstream localhost { server localhost:8081 weight=1; server 192.168.1.109:8080 weight=1; } server { listen 9000; server_name localhost; charset utf-8; location / { root html; index index.html index.htm; proxy_pass http://localhost; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~ ^/(WEB-INF)/ { deny all; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
server localhost:8081 weight=1; server localhost:8081 weight=1; <span style="font-family: Arial, Helvetica, sans-serif;">server 192.168.1.109:8080 weight=1; 此项更改为自己的服务器ip和端口号,weight表示服务器被访问的频率,相同表示频率相等。</span>
4.进入nginx目录下启动nginx:
nginx -s reload 为重新启动nginx进程
nginx -s stop为关闭nginx进程
nginx -t 命令出现如上图所示表示配置文件无错误
5.访问页面:
192.168.1.109服务器上的首页(页面有些敏感信息,故显示一个小角)
我自己本机去掉(css和改变内容的登陆页面)
不停访问该页面,可发现随机出现以上情况,由此可见,nginx充当反向代理服务器和负载均衡已经实现。
若不理解反向代理等知识,请看我转载的一篇经典文章:正向代理,反向代理和透明代理的原理和区别!
相关文章推荐
- tomcat 使用问题
- nginx和tomcat负载均衡后session无法共享的解决方案
- web tomcat 7可以运行,部署weblogic10.3不行
- Tomcat启动报错,The CATALINA_HOME environment variable is not defined correctly
- Eclipse导入Tomcat源码
- Tomcat启用Gzip压缩
- Tomcat7源码的环境搭建
- apache2.2.25+mod_jk-apache-2.2.2.so+apache-tomcat-7.0.56集群
- Tomcat Cannot assign requested address: JVM_Bind 非端口占用冲突
- tomcat结合nginx使用小结
- windows下启动tomcat
- zabbix之通过jmx监控tomcat
- eclipes+tomcat+spingmvc 发布到阿里云服务器mysql遇到问题
- linux apache+tomcat集群+负载均衡
- tomcat 启动失败Connection timed out??
- Tomcat配置
- nginx和Tomcat集成后发生的重定向问题分析和解决
- tomcat报错:This is very likely to create a memory leak问题解决
- tomcat 启动一闪而过
- tomcat集群的session管理