apache2mod-proxynitrogen

Using Apache mod-proxy with Erlang 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?


Solution

  • 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.