即时更改 Tomcat 端口

编程入门 行业动态 更新时间:2024-10-25 23:23:30
本文介绍了即时更改 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 端口

本文发布于:2023-08-07 19:42:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1321382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   Tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!