1.配置nginx.conf
upstream tomcatserver1 {
server 192.168.1.160:8081; //服务器地址
}
upstream tomcatserver2 {
server 192.168.1.160:8082;
}
server {
listen 80;
server_name 8081.max.com; //域名(指向服务器ip的域名才行)
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcatserver1;
index index.html index.htm;
}
}
server {
listen 80;
server_name 8082.max.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://tomcatserver2;
index index.html index.htm;
}
}
Ps: 这样配置之后访问接口的时候需要 域名/项目名/接口
2.修改tomcat默认项目 改动配置文件server.xml
添加<Context path="" docBase="Cluster" debug="0" reloadable="true"/>节点,当中docBase为webapps中的项目。注意,<Context>一定要加在<Host>节点中。样例例如以下:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="kooun-tramgang-user" debug="0" reloadable="true"/>
只需要添加红色这行代码就行了
Ps:nginx,tomcat修改了配置文件之后都要重启一下