windows下tomcat和nginx负载均衡的简单配置!
来源:互联网 发布:nginx 静态服务器配置 编辑:程序博客网 时间:2024/06/06 03:57
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文件,如下:
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充当反向代理服务器和负载均衡已经实现。
若不理解反向代理等知识,请看我转载的一篇经典文章:正向代理,反向代理和透明代理的原理和区别!
0 0
- windows下tomcat和nginx负载均衡的简单配置!
- Windows下nginx+tomcat的负载均衡
- Windows下nginx+tomcat的负载均衡
- Windows下配置Nginx+Tomcat配置集群负载均衡
- Windows下配置Nginx+Tomcat配置集群负载均衡
- Windows下配置Nginx+Tomcat配置集群负载均衡
- Windows下用Nginx+Tomcat配置集群负载均衡
- Windows下使用Nginx+tomcat配置负载均衡
- Windows下Nginx+tomcat配置集群负载均衡
- Nginx+Tomcat配置集群负载均衡(windows)
- linux下nginx和tomcat负载均衡配置
- nginx+tomcat简单负载均衡配置
- CentOS 下 Nginx + Tomcat 配置负载均衡
- CentOS 下 Nginx + Tomcat 配置负载均衡
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 基于nginx的tomcat负载均衡和集群(超简单)
- 防止用户在页面上填写恶意代码webConfig中所做操作
- 机器学习中的相似性度量
- JS.jQuery获取浏览器参数
- 抽象 多态 继承 封装 接口 单例
- linux平台上image文件挂载的方法
- windows下tomcat和nginx负载均衡的简单配置!
- 关于listview加载图片时oom的解决方案
- 资金管理系统中的基础财务记账规则
- jstl的学习
- ps 滤镜特效
- Linux/CentOS 升级C基本运行库CLIBC的注意事项(当想解决GLIBC_2.x找不到的编译问题)
- quartz触发器失败策略
- linux服务器备份(python)
- 杭电1029——出现(n+1)/2次的数