骑驴会友 發表於 2019-12-12 15:32:00

Tomcat配置域名、ip访问及解决80端口冲突

<p>&nbsp;</p>
<p style="margin: 5px 0">1.先在tomcat下的conf下找到server.xml文件,用记事本打开后,首先对端口号进行修改,以前一直以为8080是默认的端口号,其实默认的端口号是80</p>
<pre class="brush:xml;toolbar:false">&lt;Connector&nbsp;port="80"&nbsp;maxHttpHeaderSize="8192"&nbsp;maxThreads="150"&nbsp;minSpareThreads="25"&nbsp;maxSpareThreads="75"&nbsp;enableLookups="false"&nbsp;redirectPort="8443"&nbsp;acceptCount="100"&nbsp;connectionTimeout="20000"&nbsp;disableUploadTimeout="true"&nbsp;/&gt;端口搞定后,我们就可以直接配置域名访问了</pre>
<p style="margin: 5px 0"><strong>域名可以访问ip无法访问</strong></p>
<p style="margin: 5px 0">在Tomcat下面配置域名(如:www.zjhuiwan.com)的时候,同时又不希望客户通过我们网站的IP或者域名访问到Tomcat默认的ROOT,配制方法如下:</p>
<p style="margin: 5px 0">2、在server.xml中将原有的&lt;Engine name="Catalina" defaultHost="localhost"&gt;修改为&lt;Engine name="Catalina"&nbsp;defaultHost="www.zjhuiwan.com"&gt;,defaultHost可以是IP或域名。</p>
<p style="margin: 5px 0">3、在server.xml中将原有的&lt;Host name=“localhost“ appBase=“webapps“ ……&gt;修改为&lt;Host&nbsp;name=“www.zjhuiwan.com“ appBase=“webapps“……&gt;,name后面可以填IP也可以是域名。</p>
<p style="margin: 5px 0">4、在&lt;Host&gt;中添加:&lt;Context &nbsp;path="/别名" &nbsp;docBase="项目路径/项目名" /&gt;(注意:自己输,粘贴可能报错(1字节的UTF-8序列的字节1无效))</p>
<p style="margin: 5px 0">&lt;Context path="" docBase="Tea"/&gt;(Tea项目在webapps下)</p>
<p style="margin: 5px 0">  其中docBase中的内容就是你希望的打开您的域名(www.zjhuiwan.com) 的时候映射到的目录和默认的网页(如:index.jsp)</p>
<p style="margin: 5px 0">并且可以同时配置多个&lt;Host&gt;,也可为同一个项目配置域名和IP访问</p>
<p style="margin: 5px 0">5、最终我们要在本地访问域名,因无域名解析服务器,所以在hosts上配,来模拟dns解析。还得修改相关HOST文件。。打开C:/WINDOWS/system32/drivers/etc/hosts</p>
<p style="margin: 5px 0">加上</p>
<p style="margin: 5px 0">127.0.0.1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;www.zjhuiwan.com (注意:去掉“#”)</p>
<p style="margin: 5px 0">6、启动Tomcat服务器,就可以直接敲入域名访问你要访问的地址了。</p>
<pre class="brush:xml;toolbar:false">&lt;Engine&nbsp;name="Catalina"&nbsp;defaultHost="www.zjhuiwan.cn"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Realm&nbsp;className="org.apache.catalina.realm.LockOutRealm"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Realm&nbsp;className="org.apache.catalina.realm.UserDatabaseRealm"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resourceName="UserDatabase"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Realm&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Host&nbsp;name="www.zjhuiwan.cn"&nbsp;&nbsp;appBase="webapps"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unpackWARs="true"&nbsp;autoDeploy="true"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Context&nbsp;path=""&nbsp;docBase="zjblog"&nbsp;debug="0"&nbsp;reloadable="true"/&gt;                <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Valve&nbsp;className="org.apache.catalina.valves.AccessLogValve"&nbsp;directory="logs"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;prefix="localhost_access_log"&nbsp;suffix=".txt"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pattern="%h&nbsp;%l&nbsp;%u&nbsp;%t&nbsp;&amp;quot;%r&amp;quot;&nbsp;%s&nbsp;%b"&nbsp;/&gt;<br>                &lt;!--配置其他位置的静态资源访问--&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Context&nbsp;docBase="/usr/uploadFile/img"&nbsp;path="/blogImg"&nbsp;reloadable="true"/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Host&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Engine&gt;</pre>
<p style="margin: 5px 0">&nbsp;</p>
<p style="margin: 5px 0"><strong>域名ip都可以访问</strong></p>
<p style="margin: 5px 0"><strong>只需要添加&lt;Alias&gt;www.zjhuiwan.cn&lt;/Alias&gt;&nbsp;即可。</strong></p>
<pre class="brush:xml;toolbar:false">&nbsp;&nbsp;&nbsp;&nbsp;&lt;Engine&nbsp;defaultHost="localhost"&nbsp;name="Catalina"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Realm&nbsp;className="org.apache.catalina.realm.LockOutRealm"&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Realm&nbsp;className="org.apache.catalina.realm.UserDatabaseRealm"&nbsp;resourceName="UserDatabase"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Realm&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Host&nbsp;appBase="webapps"&nbsp;autoDeploy="true"&nbsp;name="localhost"&nbsp;unpackWARs="true"&gt;<br>                &lt;Alias&gt;www.zjhuiwan.cn&lt;/Alias&gt;<br>                &lt;Context&nbsp;docBase="zjblog"&nbsp;path=""&nbsp;reloadable="true"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;Valve&nbsp;className="org.apache.catalina.valves.AccessLogValve"&nbsp;directory="logs"&nbsp;pattern="%h&nbsp;%l&nbsp;%u&nbsp;%t&nbsp;&amp;quot;%r&amp;quot;&nbsp;%s&nbsp;%b"&nbsp;prefix="localhost_access_log."&nbsp;suffix=".txt"/&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Host&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/Engine&gt;</pre>
<p style="margin: 5px 0">&nbsp;</p>
<p style="margin: 5px 0"><strong>&nbsp;</strong></p>
<p style="margin: 5px 0"><strong>&nbsp;</strong></p>
<p style="margin: 5px 0">有时候,80端口会被其他的进程占用,这时候就需要结束原来的进程或修改为其他端口号</p>
<h1 style="font-size: 28px; line-height: 1.5; margin: 10px 0; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: rgba(40, 85, 126, 1)"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">I.Port80简介:</span></h1>
<p style="margin: 5px 0"><span style="font-family: &quot;Microsoft YaHei&quot;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="font-size: 15px">&nbsp;80端口是为HTTP(HyperText Transport Protocol)即超文本传输协议开放的,此为上网冲浪使用次数最多的协议,主要用于WWW(World Wide Web)即万维网传输信息的协议。</span></span><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 15px">可以通过HTTP地址(即常说的“网址”)加“: 80”来访问网站,因为浏览网页服务默认的端口号都是80,因此只需输入网址即可,不用输入“: 80”了。</span></p>
<h1 class="para" style="font-size: 28px; line-height: 1.5; margin: 10px 0"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">II.问题描述:</span></h1>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">  <span style="font-size: 15px">80端口是一个最为频繁访问的端口号,甚为程序员开发更是经常遇到,比如我们最熟悉的数据库系统服务进程就是默认访问该端口的,还有比如Ngnix服务器默认端口也是80,所以当使用ngnix时发生端口号冲突了,应该怎么办呢?以下见析。</span></span></p>
<h1 style="font-size: 28px; line-height: 1.5; margin: 10px 0"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">III.原因:</span></h1>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">  <span style="font-size: 15px">主要是与http协议有关的进程,进行网上访问的系统级别的进程最频繁占用80端口。比如Http.sys。它是http&nbsp;API的驱动组件,Http栈服务器。如果该端口被Http.sys占用,说明一些正在使用http.sys的应用程序在运行。</span></span></p>
<h1 style="font-size: 28px; line-height: 1.5; margin: 10px 0"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">IV.解决办法:</span></h1>
<h2 style="margin: 10px 0; font-size: 21px; border-bottom: 1px solid rgba(102, 102, 102, 1); line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt">  <span style="font-size: 15px">1)使用命令查看哪个线程占用80端口</span></span></h2>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    win+R调出doc窗口,输入cmd,继续输入"netstat -ano | more"或者“netstat -aon”</span></span></p>
<h2 style="margin: 10px 0; font-size: 21px; border-bottom: 1px solid rgba(102, 102, 102, 1); line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">  &nbsp; 2)寻找端口号</span></span></h2>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    找到“本地地址”栏为0.0.0.0:80的一行,在行的末尾有pid(进程id)为“4”。</span></span></p>
<h2 style="margin: 10px 0; font-size: 21px; border-bottom: 1px solid rgba(102, 102, 102, 1); line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">  3)打开任务管理器(ctrl+alt+del)<br></span></span></h2>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    查看pid为4的线程,一般会显示system占用;自然system是无法直接kill的。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    使用netsh命令查看端口使用状态:”netsh http show servicetstate“。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    可以看到有两个进程正在使用http功能。分别为 3164和3196。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    其中3196是sql server的report服务;进程3164对应的是一个svchost服务。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    两者都可以关闭,数据库服务的见下述解决方式。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">   【扩展】:</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    但是,50秒之后端口又会自动被占用了。【重新占用】</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    从procmonitor中可以看到,每次关闭服务 BranchCache 每50s后就会继续被svchost给调用起来。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    通过services表(服务表)中,我们发现这里的BranchCache&nbsp;依赖了HTTP.SYS这个内核驱动。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    手动禁用即可。</span></span></p>
<h2 style="margin: 10px 0; font-size: 21px; border-bottom: 1px solid rgba(102, 102, 102, 1); line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">  4)多版本解决方案:</span></span></h2>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    【分析】:</span></span></p>
<p style="line-height: 1.5">     1)SQL Server导致。其中很有可能是SQL Server Reporting Services (MSSQLSERVER),它是 SQL Server 的日志系统。</p>
<p style="line-height: 1.5">     2)IIS 服务。如果你电脑安装了这个,很有可能它在运行着,那么它就占用着80端口。(打开IIS的方法:打开控制面板,点“卸载”,</p>
<p style="line-height: 1.5">      弹窗里左侧有一个“打开或关闭windows功能”,再点开会有一个弹窗,找“Internet信息服务”,找到 Internet Information Services,</p>
<p style="line-height: 1.5">      点加号展开!因为直接点这个大项前面的小方块,FTP服务器选项没反应,我图里的这几个都勾上就行了。</p>
<p style="line-height: 1.5">      <img src="https://www.zjhuiwan.cn/ueditor/jsp/upload/image/20191212/1576134554428065099.png"></p>
<p style="line-height: 1.5">      然后右下角点确定,IIS开启成功了。</p>
<p style="line-height: 1.5">      关上:开始图标那个win旁边有个圈圈,点开输入iis回车就能打开IIS管理器,右击,点停止,IIS就算关上了。(win10系统)</p>
<p style="line-height: 1.5">     3)其他。(比如,迅雷等程序或者一些其他有上传功能的软件都会占用电脑的80端口)</p>
<h3 style="font-size: 16px; border-bottom: 1px solid rgba(170, 170, 170, 1); line-height: 1.5; margin: 10px 0"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    A.已知为数据库进程占用,最常见:</span></span></h3>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    i.查看“任务管理器”进程栏或者详细信息栏,有没有数据库有关的进程,直接kill就行。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    ii.打开【管理】-&gt;【服务和应用程序】-&gt;【服务】-&gt;找到“SQL Server Reporting Service",禁用或者手动皆可。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    以上可以解决基本上90%左右的占用问题。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    (一般来说,可能是近期安装了数据库或者升级了数据库等软件造成的,</span></span><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">系统占用的端口一般都是微软官方的产品占用的。)</span></span></p>
<h3 style="font-size: 16px; border-bottom: 1px solid rgba(170, 170, 170, 1); line-height: 1.5; margin: 10px 0"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    B.未知进程,即system进程(win7 system默认占用):</span></span></h3>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    i.禁用http.sys</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    输入net stop http,然后确认继续操作,在输入Sc config http start= disabled即可停止该项服务。</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    ii.调出注册表</span></span></p>
<p style="line-height: 1.5"><span style="font-family: &quot;Microsoft YaHei&quot;; font-size: 14pt"><span style="font-size: 15px">    打开RegEdit:【开始】-&gt;【运行】-&gt;输入【regedit】调出 ”注册表“,</span></span></p>
<p style="line-height: 1.5">    找到”HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesHTTP“,</p>
<p style="line-height: 1.5">    &nbsp;找到一个DWORD值Start,将其改为0,重启电脑,System进程将不会占用80端口。</p>
<p style="line-height: 1.5">    【备注】:杀掉进程的命令:taskkill /pid 4 /f ,其中 /f 表示强制关闭该进程。</p>
<p style="margin: 5px 0">&nbsp;</p>

</div>
<div id="MySignature" role="contentinfo">
    一个java小菜鸡的进阶之路,我的个人博客:http://www.zjhuiwan.cn 欢迎访问!<br><br>
来源:https://www.cnblogs.com/sunonzj/p/12029507.html
頁: [1]
查看完整版本: Tomcat配置域名、ip访问及解决80端口冲突