如果要部署多个实例,则必须每个Server的端口号不一样
第一个tomcat的配置文件 port=8005,应用访问端口8081
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
第2个tomcat的配置文件 port=8006,应用访问端口号8081
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
Nginx相关配置
#==============================start,全局块,从开始到events块之间的内容=======
#运行用户
#user nobody;
# work进程数量,通常设置为何cpu数量相等
worker_processes 1;
# 全局错误日志及pid文件位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
# ============================end,全局块====================
# =============================start,events事件块(影响nginx服务器和用户的网络连接)===
events {
worker_connections 1024;
}
#==============================end,events时间块==============
#==============================start,http块(nginx服务器中配置最频繁的部分,端口监听,请求转发等)====================
http {
# 引入mime类型定义文件
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;
#io密集型的可以关掉,有助于性能的提高
sendfile on;
#tcp_nopush on;
#链接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
#是否开启了
#gzip on;
#
# 负载均衡
upstream lagouServer{
# ip_hash;
server 127.0.0.1:8080 weight=2;
server 127.0.0.1:8081;
}
# tomcat的host
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# tomcat的 context
# 默认请求
#
# 需求一:默认的nginx,访问 http://192.168.56.101:9003 ---> http:127.0.0.1:8080
#location / {
# #proxy_pass http://127.0.0.1:8080;
# root html; #默认的网站根目录位置
# # index index.html index.htm; #欢迎页
#}
location / {
root html;
index index.html index.htm;
proxy_set_header Host $host;
proxy_pass http://lagouServer;
}
# 需求二:
# 访问http:192.168.56.101:9003/abc -----> http://127.0.0.1:8080/
# 访问http:192.168.56.101:9003/def -----> http://127.0.0.1:8081/
location /abc{
proxy_pass http://127.0.0.1:8080/;
}
location /def{
proxy_pass http://127.0.0.1:8081/;
}
# 需求三:
# 访问http:192.168.56.101:9003/zzz
# ---> 随机访问 127.0.0.1:8080
# ---> 随机访问 127.0.0.1:8081
# ---> 随机访问 127.0.0.1:8082
location /zzz{
proxy_pass http://lagouServer/;
}
# 需求四:静态资源文件
location /static{
root staticData;
}
location /favicon.ico{
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
发布步骤
1、使用rz命令,把文件上传到webapps目录中
2、修改conf文件
3、添加一个站点
4、启动Tomcat