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

访问测试:

 

posted on 2019-01-17 22:32  苦咖啡~~  阅读(176)  评论(0编辑  收藏  举报