gpt4 book ai didi

virtualhost - 我们可以在tomcat的server.xml文件中包含文件来配置虚拟主机吗

转载 作者:行者123 更新时间:2023-12-02 19:54:01 26 4
gpt4 key购买 nike

我的 tomcat 中有 server.xml 文件的以下部分。

<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>

<Host name="mydomain1" appBase="d1"
unpackWARs="true" autoDeploy="true">
<Alias>xyz-mydomain1.com</Alias>
<Alias>abc.mydomain1.com</Alias>


<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="d1_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>

<Host name="mydomain2" appBase="d2"
unpackWARs="true" autoDeploy="true">


<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="d2_access_log" suffix=".txt"
pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>

有什么方法可以通过对我可以放在 tomcat 的 conf 文件夹中的一些 xml 文件使用 include 选项来包含额外的主机条目。

最佳答案

我不确定这是否是您要查找的内容,但您可以通过 XML 实体包含将文件包含在 tomcat XML 中。不过,您必须确保它们位于用户具有读取权限 的位置。 (您不能包含用户没有读取权限的文件。)

Here’s how to include a file in your Tomcat’s server.xml. Edit yourserver.xml, and at the very top of the file, right after any <?xml>declaration line (that’s optional), put the following DOCTYPEdeclaration to define a file entity:

    <?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE server-xml [
<!ENTITY connector1-config SYSTEM "connector1-config.xml">
]>

This markup means that this document’s name is “server-xml”, and we’redefining a new entity named “connector1-config” which the XML parsercan find in a file named “connector1-config.xml”. You can name yourentities anything you want, as long as the parser accepts thecharacters you use. I suggest just using alpha-numeric characters anddash, to keep it simple. It turns out that if you don’t specify anabsolute path to the file, the parser will look for the file in thesame directory as the file that includes it, so the parser will lookin Tomcat’s conf/ directory.

But, we haven’t yet used the connector XML entity we defined at thetop of server.xml. At the point in the file where we want the parserto insert the connector’s XML, we need only to write“@connector1-config;” like this:

<Server ...>
<Service ...>

<!-- See conf/connector1-config.xml for this <a href="https://www.mulesoft.com/exchange#!/?types=connector" target="_blank" rel="" title="Cloud Connectors" >connector's</a> config. -->
&connector1-config;

</Service>
</Server>

Then, in your connector1-config.xml file put the following XMLsnippet:

    <!-- Define a non-SSL Coyote HTTP/1.1 <a href="https://www.mulesoft.com/exchange#!/?types=connector" target="_blank" rel="" title="Cloud Connectors" >Connector</a> on port 8089 -->
<Connector port="8089" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Using this include mechanism, you may include any file that resides inthe same directory as Tomcat’s server.xml file.

If, instead, you want to include a file in another directory, whereyour Tomcat JVM user has read permission to the file, you can specifyan absolute path when you define the entity, like this:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE server-xml [
<!ENTITY connector1-config SYSTEM "file:///opt/myproject/connector1-config.xml">
]>

You use this entity the same way, just by placing“&connector1-config;” wherever you want the XML snippet included.

要包含多个文件,请尝试以下操作:

    <?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE server-xml [
<!ENTITY file1 SYSTEM "file1.xml">
<!ENTITY file2 SYSTEM "file2.xml">
]>

然后在文件中您希望解析器插入相应文件代码的位置试试这个:

<Server ...>
<Service ...>

<!-- See conf/file1.xml for this -->
&file1;
<!-- See conf/file2.xml for this -->
&file2;

</Service>
</Server>

我的回答主要基于这个 post by jasonb . 请访问 jasonb 的博客并支持他的工作。我在这里引用了他的帖子,因此即使博客被删除,社区也可以访问它。

关于virtualhost - 我们可以在tomcat的server.xml文件中包含文件来配置虚拟主机吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57485833/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com