我想将 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 端口
发布评论