我在一台服务器上有一个静态 IP,该 IP 可通过互联网公开访问。我在该服务器上运行 Apache WebServer。
我怎样才能让 3 个 Web 应用程序(在 Tomcat 上)在 3 台不同的内部网 PC 上运行 - 并使用我拥有的一个可公开访问的 IP - 可通过互联网访问?
值得注意的是,静态 IP 服务器可以有两个网络适配器,并且肯定也可以访问内网 PC。
请提供解决此问题的最佳方法。非常感谢。
答案1
我的tomcat虚拟主机设置:
首先为 apache 启用 mod_jk:
a2enmod mod_jk
然后重新启动 apache
猫/等/ apache2 /站点已启用/ tomcat:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /usr/share/tomcat5.5/webapps/mydomain1.com
ServerName mydomain1.com
JkMount /* mydomain1
ErrorLog /usr/share/tomcat5.5/logs/mydomain1.com-error_log
CustomLog "|/usr/sbin/rotatelogs -l /usr/share/tomcat5.5/logs/mydomain1.com-access-%Y-%m-%d.log 86400" combined
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /usr/share/tomcat5.5/webapps/mydomain2.com
ServerName mydomain2.com
JkMount /* mydomain2
ErrorLog /usr/share/tomcat5.5/logs/mydomain2.com-error_log
CustomLog "|/usr/sbin/rotatelogs -l /usr/share/tomcat5.5/logs/mydomain2.com-access-%Y-%m-%d.log 86400" combined
</VirtualHost>
猫/etc/apache2/workers.properties
workers.tomcat_home=/usr/share/tomcat5.5/
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=mydomain1, mydomain2
worker.lic.type=ajp13
worker.lic.host=mydomain1.com
worker.lic.port=8009
worker.lic.lbfactor=1
worker.wideok.type=ajp13
worker.wideok.host=mydomain2.com
worker.wideok.port=8009
worker.wideok.lbfactor=1
猫/usr/share/tomcat5.5/conf/server.xml
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
<GlobalNamingResources>
<Environment name="simpleValue" type="java.lang.Integer" value="30"/>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" maxHttpHeaderSize="8192"
maxThreads="150000" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="3600000" disableUploadTimeout="true" />
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" SSLEnabled="true"
keystoreFile="/usr/share/tomcat5.5/webapps/somedomain.com/ROOT/WEB-INF/ssl/sms_ssl.key" keystorePass="changeit"
sslProtocol="SSL" />
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="localhost">
<Listener className="org.apache.jk.config.ApacheConfig"
modJk="/usr/lib/apache2/modules/mod_jk.so"
workersConfig="/etc/apache2/workers.properties"/>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
<Host name="mydomain1.com"
appBase="/usr/share/tomcat5.5/webapps/mydomain1.com"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
</Host>
<Host name="mydomain2.com"
appBase="/usr/share/tomcat5.5/webapps/mydomain2.com"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
</Host>
</Engine></Service></Server>
以及 /usr/share/tomcat5.5/webapps 的目录结构
/usr/share/tomcat5.5/webapps/
ROOT/WEB-INF
ROOT/index.jsp
/usr/share/tomcat5.5/webapps/mydomain1.com/
ROOT/WEB-INF
ROOT/index.jsp
/usr/share/tomcat5.5/webapps/mydomain2.com/
ROOT/WEB-INF
ROOT/index.jsp
希望有帮助:)
答案2
如果您使用 mod_jk 或 mod_proxy 连接 Apache httpd 和 Tomcat,这非常容易做到。
首先,为每个 Tomcat 分配一个路径,例如
http://example.com/app1
http://example.com/app2
以 mod_jk 为例,您需要为每个 Tomcat 设置 worker(worker1、worker2),然后将请求重定向到相应的 worker,如下所示,
JkMount /app1/* worker1
JkMount /app2/* worker1
如果由于某种原因您不想分配路径,则需要获取多个域名,每个 Tomcat 一个,并使用 mod_rewrite 根据HTTP_HOST
标头值在内部注入路径。
答案3
查看这里