码迷,mamicode.com
首页 > 其他好文 > 详细

nginx+tomcat实现简单的负载均衡

时间:2019-01-17 23:44:45      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:get   str   mime   tom   syntax   www.   ups   live   col   

host1:10.0.0.10(部署nginx和tomcat)

host2:10.0.0.11(部署tomcat)

平台环境(2主机一样)

[root@smp ~]# uname -r
3.10.0-862.el7.x86_64
[root@smp ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)

host1及host2上操作:

安装tomcat

https://www.cnblogs.com/liliyang/p/9742284.html

按照上面的博文将将两台机器上的tomcat均部署好,

然后访问 

技术分享图片技术分享图片

 

host1上安装nginx

yum install  wget -y

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum install  nginx  -y

cat  /etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 2048; use epoll; } http { log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; upstream tomcatservers {     #这里注意tomcatserver为池的名称,这里的名称可任意取,但是名称内不能有下划线(有的书中使用了下划线)!!!!!!! server 10.0.0.10:8080 weight=1; server 10.0.0.11:8080 weight=1; } server { listen 80 default_server; listen [::]:80 default_server; server_name 10.0.0.10; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://tomcatservers;    #这里的名称必须是服务池的名称 proxy_redirect default; }                          #除了红色部分其余均为系统默认配置 error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }

[root@smp nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@smp nginx]# systemctl start nginx

访问测试:

技术分享图片

 

nginx+tomcat实现简单的负载均衡

标签:get   str   mime   tom   syntax   www.   ups   live   col   

原文地址:https://www.cnblogs.com/liliyang/p/10285318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!