您的位置:首页 > 运维架构 > Tomcat

Tomcat服务器配置,二级域名,域名访问

2016-04-26 14:26 477 查看

我要做:

通过域名访问网站

设置二级域名,用来访问webapps下不同的项目。

设置域名默认访问的项目

能解决问题:

阿里云/腾讯云,通过域名访问网站

二级域名设置

默认项目设置

连接到远程服务器不成功问题

域名解析问题

ps : 以上问题在问题解决中都有涉及,如果还有问题,请私我

问题一:域名解析问题

在阿里云/腾讯云中的域名管理中进行域名解析。

按照它的要求填入域名解析规则。@、www、*等等。域名解析所指向为你的外网ip地址。

此时在本地电脑dos界面上输入:
ping www.sss.com
(sss为你的域名,请修改)

如果能ping通,说明域名解析ok。(dos界面自己百度)

ps : 如果不通,请直接在dos界面中输入:
ping 115.214.214.01
(此处是你的外网ip)

问题二:二级域名设置

进入远程服务器,方式可以通过远程连接或者其他。

在tomcat文件所在目录中找到conf/server.xml。在其中修改:

<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" />
<Context path="" docBase="C:\Program Files\apache-tomcat-7.0.69\webapps\SHstrutshib"  reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

<!-- manger -->
<Host name="manager.mark.me" debug="0" appBase=""
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">

<Alias>manager.mark.me</Alias>

<Context path="" docBase="C:\Program Files\apache-tomcat-7.0.69\webapps\manager"  reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

<Host name="sh.mark.me" debug="0" appBase=""
unpackWARs="true"
xmlValidation="false" xmlNamespaceAware="false">

<Alias>sh.mark.me</Alias>

<Context path="" docBase="C:\Program Files\apache-tomcat-7.0.69\webapps\SHstrutshib"  reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>


同时将端口设置成:80 。设置80是在浏览器中不设置www.xxx.com:8080/端口访问,直接www.xxx.com访问

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />


如果所有的这些配置成功表示:

你可以在电
4000
脑上通过输入以下域名访问不同项目:

sh.mark.me 访问webapps中的SHstrutshib项目

manager.mark.me 访问webapps中的manager项目

问题三、配置域名默认项目,即不显示tomcat的主界面

在server.xml中配置。

<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" />
<Context path="" docBase="C:\Program Files\apache-tomcat-7.0.69\webapps\SHstrutshib"  reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>


这是每一个tomcat都默认自带的一个host,所以只要在其中加入一条:

<Context path="" docBase="C:\Program Files\apache-tomcat-7.0.69\webapps\SHstrutshib"  reloadable="true" caseSensitive="false" debug="0"></Context>


就可以做到访问域名www.mark.me直接访问SHstrutshib项目
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息