Basic merb deployment using Apache mod_proxy

May 14, 2008 | Author: sci-dev | Publisher: hassox

It is a basic configuration, though it may face production environments as well.

For working configuration you will need:
- Apache 2.2 with mod_proxy and mod_proxy_http
- write access to httpd.conf (as well as rights to restart apache server)
- merb application

Go to merb app root dir, start app. By default it will listen on port 4000.
To make it listen on another port, use:
merb -p port_number

Now open httpd.conf, and place this code after modules loading:

<Proxy balancer://host_name> BalancerMember http://127.0.0.1:port_name </Proxy>

Next, in your virtual hosts file, add 2 lines to your host configuration:

ProxyPass / balancer://host_name/ ProxyPassReverse / balancer://host_name/

Your host configuration may look like this:

<VirtualHost *:80>
  ServerAdmin     admin@host_name
  DocumentRoot    /path/to/your/host_name
  ServerName      host_name
  ErrorLog        /path/to/your/error.log
  ProxyPass         / balancer://host_name/
  ProxyPassReverse  / balancer://host_name/
</VirtualHost>

After apache restarting, you should see your app in browser at the address http://host_name

Comments

On May 22, 2008 at 05:02 jnicklas says:

I’m no Apache whizz, but wouldn’t this make merb serve static files? That¨s probably not desirable, and should be relatively easy to fix. For a cluster, you could do:

  1. Rewrite index to check for static RewriteRule /$ /index.html [QSA]
  1. Rewrite to check for cached pages RewriteRule ^([.]+)$ $1.html [QSA]
  1. Redirect all non-static requests to cluster RewriteCond /{REQUEST_FILENAME} !-f RewriteRule /(.)$ balancer://my_cluster%{REQUEST_URI} [P,QSA,L]

Also if you are running merb on only a single port, you really don’t need the proxy balancer. Just use a normal proxy pass, not sure if these rewrite rules are correct:

  1. Rewrite to check for static RewriteRule ^/$ /index.html [L]
  1. Rewrite to check for cached pages RewriteRule ^([.]+)$ $1.html [L]
  1. Let apache serve static files RewriteCond {DOCUMENT_ROOT}{REQUEST_URI} -f RewriteRule (.) $1 [L]
ProxyPass / http://127.0.0.1:8000/
                ProxyPassReverse / http://127.0.0.1:8000/

On May 22, 2008 at 05:05 jnicklas says:

Ohh, that got nicely mangled, what formatting is used here? Anyway, here’s a pastie:

http://pastie.caboo.se/201469

On August 23, 2008 at 09:10 taerb says:

This is exaclty what I needed and worked great for me.

Sign in to make your voice heard