在Sentos上运行两个tomcat;
方法,修改server.xml文件的端口号。
在Nginx的配置文件中添加一个Server:
#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;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name www.test.nginx.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#lanqie change
#make 1 domain for application
server {
listen 80;
server_name www.eshop.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html2;
index index2.html index2.htm;
}
}
#@lanqie
#make 2 tomcat for application
upstream tomcats{
server 192.168.10.128:8080;
server 192.168.10.128:8081;
}
server {
listen 80;
server_name www.eshop.tomcat.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcats;
index index2.html index2.htm;
}
}
}
以上为虚拟机环境。
当本地访问
www.eshop.tomcat.com
时Nginx会自动在2个tomcat中切换
当然,前提要在hosts文件中解析域名:
# Copyright (c) 1993-2009 Microsoft Corp.
192.168.10.128 www.test.nginx.com
192.168.10.128 www.eshop.com
192.168.10.128 www.eshop.tomcat.com