一、修改改端口
1、修改默认访问端口8080,改为80
# vim /usr/local/tomcat/conf/server.xml (路径是自己的安装目录)
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> 修改端口 <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> 这样的话,在输入127.0.0.1之后就可以省略:80端口
二、修改域名访问
1、修改配置
# vim /usr/local/tomcat/conf/server.xml (路径是自己的安装目录)
添加HOST
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
改为:
<Host name="www.myweb.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
三、一个tomcat服务器上部署多个Web项目,不同域名访问
需要修改conf下的server.xml
1、不同端口访问内容相同
<Service name="Catalina">
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="808080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2.不同的域名访问不同的内容,端口相同
<Host name="www.myweb1.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="onefolder" debug="0" reloadable="true" /> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
<Host name="www.myweb2.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="twofolder" debug="0" reloadable="true" /> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
注意:2个不同域名访问相同端口的内容不同,但是如果还会使用ip访问的话,还需要在加上一个Host,
如:使用ip访问的话去访问onefolder;ip访问其host name就是localhost
3.配置 conf/server.xml 文件注意事项
增加 Context 节点,并指定 docBase 为非 webapps 的子目录(建议)
1.新建 ${CATALINA_HOME}/myapps/app1 目录;
2.修改 conf/server.xml 文件,配置 Context 节点,指定 docBase=“${CATALINA_HOME}/myapps/app1”;这里的 ${CATALINA_HOME} 为 tomcat 安装路径,使用时需替换为绝对路径;
3.将 app1.war 放到 ${CATALINA_HOME}/myapps/app1/ 目录下;
4.通过命令 jar xvf App1.war 解压 war 包到当前目录;
5.启动 tomcat;
6.后续 war 包有更新时,重复步骤3、4,不需要再执行第5步,tomcat 会自动重新部署。
注意:docBase 需要设置为绝对路径
配置示例:
conf/server.xml 文件中的 Host 节点: <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"><Context path="/" docBase="/user/local/tomcat/myapps/app1" debug="0" reloadable="true"></Context> </Host>
注意:
conf/server.xml 的 Host 节点的 appBase 指定的目录表示,
这个目录下面的子目录将自动被部署为应用。
这个目录下面的.war文件将被自动解压缩并部署为应用
而 docBase 只是指向某个应用的目录,可以和 appBase 没有任何关系。特别注意,如果 docBase 指向的是 webapps 下面的目录,会导致应用被加载两次,引起一系列问题。
3、不同的域名不同端口不同内容
<Service name="Catalina1"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" 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="www.myweb1.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="/" docBase="/usr/local/tomcat/webapps/app1" debug="0" reloadable="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>
<Service name="Catalina2"> <Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="9009" protocol="AJP/1.3" 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="www.myweb2.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="/" docBase="/usr/local/tomcat/webapps/app2" debug="0" reloadable="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>
标签:HTTP,Tomcat,docBase,webapps,端口,域名,tomcat,true From: https://www.cnblogs.com/elfin/p/16800012.html