on localhost forward proxy webrick,thin, unicorn to external host.com/http-bind

Rubytastic asked:

Im working on an rails project where I need a /http-bind proxy and unable to find anything about this, or find a resource to state this is possible.
I need this forward in a development environment Know its possible to use unicorn + nginx to forward the proxy with unicorn BUT im looking for a simple fast way to do it locally in my development environment…. So, is unicorn, thin, or webrick capable of doing a http-bind proxy forward?

* host.com/http-bind ( xmpp http-bind ) already running

* localhost:3000 THIN server posts to /http-bind returns a 404 not found currently nothing mapped.

Would it be possible to forward the traffic of



my external http://host.com/http-bind ? 

My answer:

Servers like thin and webrick are great for prototyping, and unicorn and passenger are great application servers, but they are not designed to be full featured web servers. For this sort of thing you really should use an actual web server (e.g. apache or nginx with passenger) as it provides enough flexibility to do these sorts of redirects and other complex configurations you’ll need in production.

You can pretty easy throw nginx in front of thin; it would then answer on port 80 and proxy requests to thin on port 3000. A minimal sample config might look like:

upstream thin {
server {
    listen   80;
    server_name .example.com;

    access_log /var/www/myapp.example.com/log/access.log;
    error_log  /var/www/myapp.example.com/log/error.log;
    root       /var/www/myapp.example.com;
    index      index.html;

    location / {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header  Host $http_host;
        proxy_redirect    off;
        try_files $uri $uri/ @ruby;

    location @ruby {
        proxy_pass http://thin;

You could then add a location for bosh something like this:

    location /http-bind/ {
        proxy_buffering off;
        tcp_nodelay on;
        keepalive_timeout 55;
        proxy_pass http://xmpp.server:5280/xmpp-httpbind/;

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.