将 Apache mod-proxy 与 Erlang Nitrogen 结合使用

发布于 2024-12-11 17:59:26 字数 1628 浏览 0 评论 0原文

我有一个运行许多 Web 应用程序的 CentOS 机器,我使用 Apache 来代理对各种应用程序的请求。除了 Erlang Nitrogen 应用程序之外,所有这些应用程序都在工作,我似乎无法工作。

我正在以标准方式运行 Nitrogen 应用程序,可以在计算机上本地访问它: http://localhost:8000 。我已经使用 wget 验证了这一点。

这是我尝试使用的 apache 配置文件:

ProxyRequests Off
ProxyPreserveHost On

<Proxy http://my-ip:8000/*>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPass /erlang http://my-ip:8000/
ProxyPassReverse /erlang http://my-ip:8000/
ProxyPassReverse  /erlang  http://my-ip/

此设置与系统上所有其他成功工作的代理类似,只是其他应用程序没有像 Nitrogen 那样部署到其服务器的根目录。

结果是基本页面已正确下载到 Web 浏览器中,但所有附带资源却未正确下载。这给了我一个无样式的页面,其中 javascript 无法正常运行。

以下是来自 Apache 的日志:

x.x.x.x - - [timestamp] "GET /erlang HTTP/1.1" 200 2884
x.x.x.x - - [timestamp] "GET /nitrogen/jquery.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/jquery-ui.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/livevalidation.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/nitrogen.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/bert.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/jquery-ui/jquery.ui.all.css HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/nitrogen.css HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /css/style.css HTTP/1.1" 404 484

我有一个硬性要求,必须使用 Apache 作为我的代理 - 我不会为了让这个 Nitrogen 应用程序正常工作而重置所有其他应用程序。在防火墙中打开8000端口也是不可能的。

我愿意使用任何 Apache 模块(mod-rewrite 等)或任何 Apache 设置,只要它不影响其他应用程序即可。我还可以更改 Nitrogen 应用程序中的任何设置,以使其更好地与 Apache 配合使用。

如何使用 Apache 来代理/反向代理我的 Nitrogen 应用程序?

I have a CentOS box running a number of web applications and I use Apache to proxy requests to the various applications. All of them are working except an Erlang Nitrogen application which I can't seem to get working.

I am running the Nitrogen app in the standard way and it can be accessed locally on the machine at http://localhost:8000. I have verified this using wget.

Here is the apache configuration file I am trying to use:

ProxyRequests Off
ProxyPreserveHost On

<Proxy http://my-ip:8000/*>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPass /erlang http://my-ip:8000/
ProxyPassReverse /erlang http://my-ip:8000/
ProxyPassReverse  /erlang  http://my-ip/

This setup is similar to all the other successfully working proxies on the system except that the other applications are not deployed to the root of their server like Nitrogen seems to be doing.

The result is that the basic page is downloading correctly into the web browser but all of the accompanying resources are not. This gives me an un-styled page where the javascript does not function correctly.

Here is the log from Apache:

x.x.x.x - - [timestamp] "GET /erlang HTTP/1.1" 200 2884
x.x.x.x - - [timestamp] "GET /nitrogen/jquery.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/jquery-ui.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/livevalidation.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/nitrogen.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/bert.js HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/jquery-ui/jquery.ui.all.css HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /nitrogen/nitrogen.css HTTP/1.1" 404 484
x.x.x.x - - [timestamp] "GET /css/style.css HTTP/1.1" 404 484

I have a hard requirement to use Apache as my proxy - I am not going to reset up all the other applications just to get this Nitrogen application working. Opening port 8000 in the firewall is also out of the question.

I am open to using any Apache module (mod-rewrite, etc) or any Apache setting as long as it doesn't affect the rest of the applications. I can also change any settings in the Nitrogen application to get it to play nicer with Apache.

How can I use Apache to proxy/reverse proxy for my Nitrogen application?

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

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

发布评论

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

评论(3

澉约 2024-12-18 17:59:26

问题:我设置了雅司病 wiki。它的工作方式类似于 http://wiki:8080。但我想以这种方式工作(使用 apache):http://wiki.local/

解决方案:

这里是我的 Yaws Wiki 的 apache 设置(/etc/apache/sites-available/wiki):

<VirtualHost *:80>
  ServerName wiki.local
  ProxyRequests Off
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyPass / http://wiki:8080/
  ProxyPassReverse / http://wiki:8080/
</VirtualHost>

我的 Yaws wiki 设置(/etc /yaws/conf.avail/yaws-wiki.conf):

ebin_dir = /usr/lib/yaws/wiki/ebin
<server wiki>
 port = 8080
 listen = 0.0.0.0
 docroot = /var/lib/yaws-wiki
</server>

我的 /etc/hosts:

127.0.0.1 wiki
127.0.0.1 wiki.local

我已经为 apache 启用了这些 mods:

sudo a2enmod proxy
sudo a2enmod proxy_http

现在 http://wiki.local/ 工作得很好。

Problem: I set up Yaws wiki. It was working like http ://wiki:8080. But I wanted to work in this way (using apache): http ://wiki.local/

Solution:

Here my apache settings (/etc/apache/sites-available/wiki) for Yaws Wiki:

<VirtualHost *:80>
  ServerName wiki.local
  ProxyRequests Off
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyPass / http://wiki:8080/
  ProxyPassReverse / http://wiki:8080/
</VirtualHost>

My Yaws wiki setting (/etc/yaws/conf.avail/yaws-wiki.conf):

ebin_dir = /usr/lib/yaws/wiki/ebin
<server wiki>
 port = 8080
 listen = 0.0.0.0
 docroot = /var/lib/yaws-wiki
</server>

My /etc/hosts:

127.0.0.1 wiki
127.0.0.1 wiki.local

I have enabled these mods for apache:

sudo a2enmod proxy
sudo a2enmod proxy_http

Now http ://wiki.local/ works perfecly.

您确定您的 Apache 服务器可以访问这些文件吗?看起来您在第一个地址上收到了 HTTP 200,在其余地址上收到了 404。确保您指向正确的位置。 :)

Are you sure that your Apache server is allowed to access those files? It looks like you're getting a HTTP 200 on the first address and a 404 on the rest. Make sure you're pointed to the correct location. :)

失而复得 2024-12-18 17:59:26

问题是 ProxyPass 仅捕获作为对 Apache 的请求传入的链接。问题在于 html 页面中的链接指向无法请求的资源,而 ProxyPass 无法拦截它们并正确路由它们。此问题记录在此处。特别请参阅“修复 HTML 链接”部分。

我最终不得不将 mod_proxy_html 安装到 Apache 中(CentOS 没有 RPM,所以我必须使用 apxs,如上述文档所述)。之后,我必须为给我带来麻烦的资源添加一些 ProxyHTMLLinks,并添加 ProxyHTMLURLMap 指令来解释我的映射。

这是我的新配置文件:

ProxyRequests Off
ProxyPreserveHost On

<Proxy http://my-ip:8000/*>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPass /erlang http://my-ip:8000/
ProxyHTMLURLMap http://my-ip:8000 /erlang

ProxyHTMLLinks  link            href
ProxyHTMLLinks  script          src for

<Location /erlang>
  ProxyPassReverse http://my-ip:8000/
  SetOutputFilter proxy-html
  ProxyHTMLExtended On
  ProxyHTMLURLMap / /erlang/
  RequestHeader unset Accept-Encoding
</Location>

这实际上是拦截 html 文件并在所有 url 前面插入 /erlang/ 。当我在浏览器中使用显示页面源功能时,我可以看到结果。

The issue is that ProxyPass only captures links coming in as requests to Apache. What was going wrong were links in the html page were pointing to resources that could not be requested and ProxyPass wasn't able to intercept them and route them correctly. This issue is documented here. See especially the section called "Fixing HTML Links".

I ended up having to install mod_proxy_html into Apache (no RPM for CentOS so I had to use apxs like the above document explained). After that I had to add some ProxyHTMLLinks for the resources that were giving me trouble and a ProxyHTMLURLMap directive to explain my mapping.

Here is my new configuration file:

ProxyRequests Off
ProxyPreserveHost On

<Proxy http://my-ip:8000/*>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPass /erlang http://my-ip:8000/
ProxyHTMLURLMap http://my-ip:8000 /erlang

ProxyHTMLLinks  link            href
ProxyHTMLLinks  script          src for

<Location /erlang>
  ProxyPassReverse http://my-ip:8000/
  SetOutputFilter proxy-html
  ProxyHTMLExtended On
  ProxyHTMLURLMap / /erlang/
  RequestHeader unset Accept-Encoding
</Location>

What this literally does is intercept the html file and insert /erlang/ in front of all the urls. I can see the result of this when I use the show page source feature in my browser.

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