nginx:10.0.0.5
tomcat-1:10.0.0.7
tomcat-2:10.0.0.8
一键安装nginx脚本
#!/bin/bash #install nginx yum install wget gcc pcre pcre-devel openssl-devel openssl gzip make cmake zlib-devel tar lrzsz -y cd wget http://nginx.org/download/nginx-1.16.1.tar.gz useradd -s /sbin/nologin -M nginx tar zxvf nginx-1.16.1.tar.gz cd nginx-1.16.1/ ./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_mp4_module make make install echo " [Unit] Description=nginx service After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target ">/lib/systemd/system/nginx.service mkdir -p /usr/local/nginx/conf.d/ systemctl daemon-reload systemctl start nginx.service systemctl enable nginx.service
编辑nginx主配置文件
vim /usr/local/nginx/conf/nginx.conf
写入一下内容
worker_processes 1;
events {
worker_connections 10240;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream tomcat {
server 10.0.0.7:8080 weight=100 max_fails=2 fail_timeout=15;
server 10.0.0.9:8080 weight=100 max_fails=2 fail_timeout=15;
# server 10.0.0.10:8080 weight=100 max_fails=2 fail_timeout=15;
# server 10.0.0.11.23:8080 weight=100 max_fails=2 fail_timeout=15;
}
include /usr/local/nginx/conf.d/*.conf;
}编辑web网站配置文件,引用的位置为/usr/local/nginx/conf.d/
vim /usr/local/nginx/conf.d/tomcat.conf
写入以下内容
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://tomcat;
proxy_set_header host $host;
root html/;
index index.jsp index.html index.htm;
}
# location ~ .*\.(htm|html|txt|js|css|png|jpg|gif|jpeg|doc|xml)$
# {
# root /data/webapps/;
# expires 30d;
# }
}