配置虚拟主机 Apache

发布于 2024-11-26 14:52:40 字数 648 浏览 2 评论 0原文

我一直在尝试配置我的apache服务器以支持虚拟主机,这些主机然后会将端口80发出的任何请求重定向到Jboss AS中托管的不同应用程序,因此例如我的配置将是这样的:

<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass / http://localhost:8080/contextPath
ProxyPassReverse / http://localhost:8080/contextPath
ProxyPreserveHost On 
ProxyPassReverseCookiePath / / 

</VirtualHost>

但是问题是当我尝试访问 http://www.testdomain.com 时,URL 被有效重定向到本地主机: 8080 然而,我得到了重复的上下文路径。 IE:http://www.testdomain.com/contextPath/contextPath

任何想法为什么会发生这种情况。多谢。

I have been trying to configure my apache server to support virtual hosts, these hosts, would then redirect any request made at port 80 to different applications hosted in a Jboss AS, so for example my configuration would be like this:

<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass / http://localhost:8080/contextPath
ProxyPassReverse / http://localhost:8080/contextPath
ProxyPreserveHost On 
ProxyPassReverseCookiePath / / 

</VirtualHost>

However the problem is that when I'm trying to access http://www.testdomain.com, the url gets redirected effectively to localhost:8080, however, I got a duplicated context path. I.E: http://www.testdomain.com/contextPath/contextPath.

Any ideas why is this happening. Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一袭水袖舞倾城 2024-12-03 14:52:40

我遇到了同样的问题,通过在网址中添加正斜杠解决了这个问题。

ProxyPass / http://localhost:8080/contextPath/
ProxyPassReverse / http://localhost:8080/contextPath/

这为我解决了!

单个虚拟主机文件的完整示例。我有几个,每个域和子域一个。

ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName        enter.name.here
        ProxyPass         / http://127.0.0.1:8080/<contextPath>/
        ProxyPassReverse  / http://127.0.0.1:8080/<contextPath>/
        ErrorLog /var/log/apache2/somelog.log
        CustomLog /var/log/apache2/somecustom.log common
</VirtualHost>

I had the same issue and this was solved by adding forwardslashes to the urls.

ProxyPass / http://localhost:8080/contextPath/
ProxyPassReverse / http://localhost:8080/contextPath/

That solved it for me !

Full example for a single virtual host file. I have several, one for each domain and subdomain.

ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName        enter.name.here
        ProxyPass         / http://127.0.0.1:8080/<contextPath>/
        ProxyPassReverse  / http://127.0.0.1:8080/<contextPath>/
        ErrorLog /var/log/apache2/somelog.log
        CustomLog /var/log/apache2/somecustom.log common
</VirtualHost>
桃气十足 2024-12-03 14:52:40

您需要删除“ProxyPass”和“ProxyPassReverse”条目,除非您确实想代理某些内容。如果jboss AS位于另一台服务器上,那么您需要保留代理条目,但在我看来,如果内容位于一台机器上而不是多台机器上,您可能会变得太困难。

如果您希望一台服务器使用不同的基本文件夹作为 2 个不同域的根目录,则需要通过指定 DocumentRoot 参数来配置这 2 个域。

例如,如果我想在一台计算机上托管 google.com 和 yahoo.com,我的虚拟主机条目将包含:

<VirtualHost *:80>
ServerName www.google.com
DocumentRoot /var/www/Google
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
DocumentRoot /var/www/Yahoo
</VirtualHost>

然后,每台服务器的根目录将分别位于 google 文件夹和 yahoo 文件夹中。

如果您尝试代理一台完全不同的机器,那么以下内容应该有效:

<VirtualHost *:80>
ServerName www.google.com
ProxyPass / www.google.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
ProxyPass / www.yahoo.com
</VirtualHost>

您的条目具体没有多大意义。我认为它应该看起来像:

<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass /contextPath http://localhost:8080
ProxyPassReverse /contextPath http://localhost:8080
</VirtualHost>

You need to remove the "ProxyPass" and "ProxyPassReverse" entries, unless you really are trying to proxy something. If the jboss AS is on another server, then you need to retain the proxy entries, but it looks to me like you might be making it too difficult if the content is on one machine and not multiples.

If you want one server to use different base folders as the root for 2 different domains, then you would need to configure the 2 domains by specifying the DocumentRoot parameter.

for example, if I wanted to host google.com and yahoo.com on one computer, my virtualhost entries would contain:

<VirtualHost *:80>
ServerName www.google.com
DocumentRoot /var/www/Google
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
DocumentRoot /var/www/Yahoo
</VirtualHost>

Then, your root directories for each server will go in the google folder and the yahoo folder, respectively.

If you are trying to proxy a completely different machine, then the following should work:

<VirtualHost *:80>
ServerName www.google.com
ProxyPass / www.google.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
ProxyPass / www.yahoo.com
</VirtualHost>

Your entry specifically doesn't make much sense. I think it should look like:

<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass /contextPath http://localhost:8080
ProxyPassReverse /contextPath http://localhost:8080
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文