tomcat5.5域名配置

    一般情况下程序员写的程序的访问地址为http://localhost:8080/myProject/index.jsp,现在要根据域名(例:www.sohu.com)访问到项目,我使用的是windows 2003和tomcat5.5.28,配置如下:
1.在项目中的web.xml文件中设置
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
这样就访问就不用加index.jsp了。
2.在Tomcat的conf\server.xml中将
<Connector port="8080" maxHttpHeaderSize="8192"
    URIEncoding="utf-8" maxThreads="150"
    minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" redirectPort="8443" acceptCount="100"
    connectionTimeout="20000" disableUploadTimeout="true" />
的port由8080改为80,80是默认端口,这样在访问时就不用加端口号了;
3.再把这个文件里的<Host name="localhost" 一段的name改成你的域名(例如:www.sohu.com),然后在下面加一行配置如红色行     
<Host name="www.sohu.com" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
    <Context path="" docBase="./myProject" debug="0" reloadable="true" crossContext="true"/>
</Host>
4.找到C:\WINDOWS\system32\drivers\etc文件夹下的hosts文件,在
  127.0.0.1    localhost   后加一行格式为你的ip对应你的域名,例如:
  192.168.1.1  www.sohu.com
有时候hosts文件不能修改那么只要打开
"开始"->"运行"->cmd后把下面内容复制上去,回车后hosts文件就可以修改了。(代码中不要有回车)
允许修改hosts文件:echo y|cacls %windir%\system32\drivers\etc\hosts /g everyone:f
禁止修改hosts文件:echo y|cacls %windir%\system32\drivers\etc\hosts /g everyone:r
经过上四步就可以实现输入域名访问工程了,如果不行再找原因吧。

你可能感兴趣的:(tomcat,Web,xml,jsp,windows)