tomcat綁定域名后讓外網訪問的方法:
1.打開需要修改的apache-tomcat-7.0.92\conf\server.xml配置文件。
2.將protocol屬性值為HTTP/1.1的Connector元素的port屬性值改為80。
<!-- ... --><Service name="Catalina">
<!-- ... -->
<!-- 將這里的8080改為80 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!-- ... -->
3.再將Engine元素的defaultHost值改為服務器公網IP或域名。
<!-- You should set jvmRoute to support load-balancing via AJP ie :<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<!-- 將這里的defaultHost的值改為服務器的公網IP,或域名 -->
<Engine name="Catalina" defaultHost="localhost">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
4.在Host元素中將name屬性值localhost改為服務器的公網IP或域名。
?
<!-- 將這里的localhost改為公網ip或域名 --><Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- 添加Context元素,并將docBase設置為項目地址 -->
<Context path="" docBase="C:\Program Files\apache-tomcat-7.0.92\webapps\Project"/>
<!-- 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>
5.最后重啟tomcat即可。