gpt4 book ai didi

java - Tomcat,httpd : Running both at same time and calling based upon URL.

转载 作者:行者123 更新时间:2023-11-28 22:53:10 25 4
gpt4 key购买 nike

我在 Debian X64 上工作,我有 tomcat 和多个 webapps 托管,工作正常。

我有一个正在运行的 Apache 网络服务器,它托管着一个 CMS,我想在调用 www.domain-cms.com 时打开它。现在,Tomcat 有 2 个基于 URL 再次调用的网络应用程序,如 www.domain-tom1.comwww.domain-tom2.com

现在我的问题是如何同时运行两者并根据 URL 进行区分。我做了以下更改,请告诉我我缺少什么。

Tomcat 的 server.xml :

 <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat">

<Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol" compression="force" compressionMinSize="1024"
connectionTimeout="20000" maxPostSize="5242880"
URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>


<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxPostSize="5242880" SSLEnabled="true" maxThreads="200" compre$
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="keystorefile" keystorePass="PASSWORD" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>



<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
<Host name="domain-first.com" autoDeploy="true" unpackWARs="true" appBase="tooltank_webapps">
<Alias>www.domain-first.com</Alias>
<Context path=""/>
</Host>

<Host name="domain-second.com" autoDeploy="true" unpackWARs="true" appBase="aupair_webapps">
<Alias>www.domain-second.com</Alias>
<Context path=""/>


</Host>
<Connector port="8010" protocol="AJP/1.3" redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
</Engine>

apache2.conf :

我已经在其中添加了这个,但似乎是错误的,因为我想根据 URL 进行重定向,但不知道要添加什么。

<IfModule jk_module>

JkWorkersFile /etc/apache2/workers.properties
JkLogLevel INFO
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

// I think below is wrong, I want to redirect based on URL.
SetEnvIf Request_URI "/error/*" no-jk
SetEnvIf Request_URI "/blog*" no-jk

JkMount / tomcat
JkMount /* tomcat

</IfModule>
(END)

workers.properties 文件:

  worker.list=tomcat
# Set properties for worker (ajp13)

worker.worker.type=ajp13
worker.worker.host=127.0.0.1
worker.worker.port=8010
(END)

现在每当我尝试启动 Apache 时,我都会收到错误消息:

[....] Restarting web server: apache2(98)Address already in use: make_sock: could not bind to address [::]:80
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
failed!

我如何连接 Apache 服务器和 tomcat,并根据 URL 并行服务 CMS 和 Web 应用程序。请告诉我。谢谢。 :-)

最佳答案

1) 端口 80 通常由 httpd apache 服务器使用,而您将其用于 Tomcat,正如我在您的 server.xml 中看到的那样 <Connector port="80"

2)在server.xml中添加虚拟主机,以在Tomcat中指向不同的网站,例如:

<Host name="domain-tom1.com" appBase="/var/java/apache-tomcat-7.0.47/webapps/">
<Context path="" docBase="direcory-in-webapps"/>
<Alias>www.domain-tom1.com</Alias>
</Host>

<Host name="domain-tom2.com" appBase="/var/java/apache-tomcat-7.0.47/webapps/">
<Context path="" docBase="direcory2-in-webapps"/>
<Alias>www.domain-tom2.com</Alias>
</Host>

你可以在</hots>之间写这个和 </Engine>

关于java - Tomcat,httpd : Running both at same time and calling based upon URL.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34134374/

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