1.solo.war包直接解壓到root
tomcat 可以直接IP:port訪問
2.solo.war包放在webapps下面的
tomcat 可以用ip:port/solo 訪問
3.tomcat的server.xml
<Context path="" docBase="/root/tomcat8/webapps/solo.war" debug="0" reloadable="false" crossContext="true"/>
情景:root目錄是不存在的
啓動tomcat會導致生成solo目錄和ROOT目錄,但是tomcat會啓動兩次
訪問可以用 ip:port 或者 ip:port/solo 訪問
4.<Context path="" docBase="/root/tomcat8/webapps/solo" debug="0" reloadable="false" crossContext="true"/>
情景:ROOT目錄是不存在的.,solo.war解壓到/root/tomcat8/webapps/solo目錄下
啓動tomcat
訪問可以用ip:port/solo 進行訪問
5.appBase設置爲空 docBase指向war包
<Host name="localhost" appBase=""
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat8/webapps/solo.war" debug="0" reloadable="false" crossContext="true"/>
用ip端口可以直接訪問,但是會生成 ROOT目錄 默認和tomcat下面ROOT不存在(和webapps同級目錄)
├── bin
├── conf
├── lib
├── LICENSE
├── logs
├── NOTICE
├── RELEASE-NOTES
├── ROOT
├── RUNNING.txt
├── temp
├── webapps
└── work
6.tomcat配置多虛擬主機
配置多個項目然後都用域名訪問
server.xml
<Host name="www.a.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat8/webapps/solo" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/solo"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="www.b.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/root/tomcat8/webapps/sl" />
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs/sl"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
tomcat war包配置
[root@cent7proxy tomcat8]# tree webapps/
webapps/
├── sl
└── index.jsp
└── solo
└── index.jsp
nginx 的配置
[root@cent7proxy nginx.conf.d]# cat www.a.com.conf
upstream k {
server 192.168.1.207:8080;
}
server {
listen 80;
server_name www.a.com;
location ~^/ {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://k;
}
}
[root@cent7proxy nginx.conf.d]# cat www.b.com.conf
upstream s {
server 192.168.1.207:8080;
}
server {
listen 80;
server_name www.b.com;
location ~^/ {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://s;
}
}
[root@cent7proxy nginx.conf.d]#
然後域名綁定就可以訪問www.a.com 和www.b.com 了