前端代理未正确引用资源

发布于 2024-11-07 08:50:55 字数 440 浏览 7 评论 0原文

我在玩游戏之前运行前端代理遇到了很多困难。 这篇文章也在谷歌组上,我将发布收到的建议。

我正在使用 apache 和 mod_proxy,应用程序应该在“mywebsite.be/dev/app/”位置运行。它能够显示 HTML。

但是当我运行该应用程序时,所有 CSS/JS/图像都丢失了,而且所有引用都不正确。我查了一下来源,似乎 Play 没有替换 @{/pathname/to/resources} 和其他指向其正确网址的相关链接。为了让一切正常工作,所有 url 都应以“/dev/app”为前缀。这怎么能做到呢?

我尝试使用 ctxPath 进行实验,但这不是我需要的,应用程序本身运行良好,但 apache2 在反向代理中翻译所有这些 url 时出现问题。

这个问题能解决吗?我正在考虑以某种方式编辑模板系统中的 @-operator,但不可能是这样,对吧?

问候, 碧玉

I'm having quite a lot of difficulties with running a frontend proxy in front of play.
This post is also on the google group, I'll post the received suggestions on both.

I'm using apache and mod_proxy and the application is supposed to be running in a location "mywebsite.be/dev/app/". It is able to display the HTML.

But when I run the application, all the CSS/JS/images are missing, also all references are incorrect. I look up the source and it seems that Play did not replace the @{/pathname/to/resources} and other relative links to its correct url. In order to let everything work, all urls should be prefixed with "/dev/app". How can this be done?

I tried experimenting with the ctxPath, but that's not what I need, the application runs fine on its own, but apache2 has issues translating all those urls in the reverse proxy.

Can this be solved? I was thinking of somehow editing the @-operator in the templating system, but that can't be it, right?

greetings,
Jasper

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

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

发布评论

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

评论(3

巾帼英雄 2024-11-14 08:50:55

你看过这个帖子吗?我认为这是相关的。

无法生成正确的使用 Apache 作为代理时带有 playframework 的静态资源的 URL

另外,请留意 Play 1.2.2,因为它旨在解决此问题,根据我在 Play 小组中读过的帖子。

Have you looked at this post? I think it is related.

Can not generate correct URLs for static resources with playframework when using Apache as a Proxy

Also, please keep an eye out for Play 1.2.2, as this intends to solve this problem, according to a post I have read in the Play groups.

软糖 2024-11-14 08:50:55

我的一位队友给出了答案。这很简单。

如果你有 apache2 配置,而不是指向 localhost 根目录,你只需指向 localhost:9000/dev/app:

ProxyPreserveHost On
RedirectMatch /dev/app /dev/app/
<Location /dev/app/>
AuthType Basic
AuthName "Test Omgeving"
AuthUserFile /var/trac/htpasswd
Require valid-user

ProxyPass http://127.0.0.1:9000/dev/app/
ProxyPassReverse http://127.0.0.1:9000/dev/app/
</Location>

这会欺骗 apache2 认为你的 localhost 服务器中还有另一个子目录,但事实上,没有没有,但现在它引用正确,因此将所有流量转换为相应的资源。

也许不是一种优雅的做事方式,但它工作得很好:)

感谢所有的帮助。希望这篇文章可以帮助其他使用前端代理的人。

问候

One of my teammates came up with the answer. It's quite simple.

If you have your apache2 configuration, instead of pointing to the localhost root, you just point to the localhost:9000/dev/app:

ProxyPreserveHost On
RedirectMatch /dev/app /dev/app/
<Location /dev/app/>
AuthType Basic
AuthName "Test Omgeving"
AuthUserFile /var/trac/htpasswd
Require valid-user

ProxyPass http://127.0.0.1:9000/dev/app/
ProxyPassReverse http://127.0.0.1:9000/dev/app/
</Location>

This tricks apache2 in thinking that there is another subdirectory in your localhost server, but in fact, there isn't any, but now it references correctly, therefore translating all trafic to the corresponding resources.

Perhaps not the classy way to do things, but it works fine :)

Thanks for all the help. Hope this post helps other people with frontend proxies out there.

Greetings

迎风吟唱 2024-11-14 08:50:55

我建议您使用代理平衡器,因为如果您计划将来使用多个播放服务器实例,它将有助于平衡您的服务器,

 <Proxy balancer://my-balancer>
    Order deny,allow
    Allow from all
    BalancerMember url1:port route=instanceOne
    BalancerMember url2:port route=instanceTwo
    ProxySet lbmethod=bytraffic
    </Proxy>
    ProxyPass /  balancer://my-balancer/

现在它会将您的流量传递到 url1:port 或 url2:port,并且还会获取您的图像和其他静态网址

i will recommend you use proxy balancer as it will help to balance your servers if you plan to use more than one instance of play server in future

 <Proxy balancer://my-balancer>
    Order deny,allow
    Allow from all
    BalancerMember url1:port route=instanceOne
    BalancerMember url2:port route=instanceTwo
    ProxySet lbmethod=bytraffic
    </Proxy>
    ProxyPass /  balancer://my-balancer/

now it will pass your traffic to url1:port or url2:port and it will also fetch your images and other static urls

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文