linux下Nginx+Tomcat配置负载均衡
1.安装tomcat可只本地安装一个tomcat 另一个用远程的
配置 好默认直接访问单节点:8080 是可以的
2.安装nginx 上篇已讲
测试nginx 安装成功 http://localhost 出现nginx主页面即可
3.配置nginx负载均衡
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream localhost{
server 139.198.13.180:8080;
server 127.0.0.1:8080;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
运行结果刷新