即时更改 Tomcat 端口 [英] Change Tomcat port on-the-fly

查看:28
本文介绍了即时更改 Tomcat 端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 Tomcat v5.5 端口存储在环境变量中,并让 Tomcat 侦听该端口.到目前为止,我可以看到更改端口的唯一方法是修改 $CATALINA_HOME/conf/server.xml.有没有办法在启动 Tomcat 时通过提供外部值来设置端口值?我在 Solaris 上运行 Tomcat.

I'd like to store the Tomcat v5.5 port in an environment variable and have Tomcat listen on that port. So far the only way I can see to change the port is by amending $CATALINA_HOME/conf/server.xml. Is there a way to set the port value by supplying an external value when starting Tomcat? I'm running Tomcat on Solaris.

推荐答案

创建一个脚本来启动 Tomcat.在启动脚本中,导出 JAVA_OPTS 以指定 Tomcat 属性 port.http.nonssl 的值(请注意,您可以随意调用此属性).

Create a script to launch Tomcat. In the launch script, export JAVA_OPTS to specify a value for the Tomcat property port.http.nonssl (note you can call this property whatever you want).

export JAVA_OPTS=-Dport.http.nonssl=${CATALINA_BASE_PORT}

如您所见,我已将 port.http.nonssl 设置为环境变量 ${CATALINA_BASE_PORT}

As you can see, I've set port.http.nonssl to the environment variable ${CATALINA_BASE_PORT}

脚本然后启动Tomcat:

The script then launches Tomcat:

$CATALINA_HOME/bin/startup.sh

您现在需要更改 Tomcat $CATALINA_HOME/conf/server.xml 文件,以便非 SSL HTTP 连接器使用 port.http.nonssl 属性而不是一个硬编码的值.

You now need to change the Tomcat $CATALINA_HOME/conf/server.xml file so the non-SSL HTTP connector uses the port.http.nonssl property instead of a hardcoded value.

<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector port="${port.http.nonssl}" maxHttpHeaderSize="8192"
           maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
           enableLookups="false" redirectPort="8443" acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true" />

现在,只要您通过新的启动脚本启动 Tomcat,Tomcat 就会使用 ${CATALINA_BASE_PORT} 环境变量中定义的端口.

Now Tomcat will use the port defined in the ${CATALINA_BASE_PORT} environment variable whenever you start it via the new launch script.

这篇关于即时更改 Tomcat 端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆