pcg79
pcg79

Reputation: 1283

How to set up Rubber + resque_web + nginx

Using Rubber I vulcanized my existing project with resque and redis. I got it all deployed. Hitting the web_tools index showed a Resque link. But clicking on it gave me a 404.

I figured nginx didn't know what to do with "/resque" so I added the file config/rubber/role/web_tools/resque-nginx.conf with:

<% if resque_host = rubber_instances.for_role('resque_web').first %>

  <%
    @path = "/etc/nginx/rubber/tools/resque.conf"
  %>

  location /resque
  {
    proxy_pass http://<%= resque_host.full_name %>:<%= rubber_env.resque_web_port %>;
  }

<% end %>

essentially copying the haproxy-nginx.conf file from the same directory.

My first question is - why did I need to do this? Should vulcanize have done this or did I do something wrong already?

Moving on. This nginx configuration did not work. But I got a little farther, at least I'm hitting the WEBrick server now. I got a page that said:

Sinatra doesn’t know this ditty.

So I changed my config thinking that Resque's WEBrick server didn't know what /resque was:

location /resque
{
  rewrite ^/resque/(.*) /$1 break;
  proxy_pass http://<%= resque_host.full_name %>:<%= rubber_env.resque_web_port %>;
}

This works but only if I manually go to https://myhost.com/resque/overview (the link that's added by Rubber to your tools index page is just /resque). But all the other links (including any CSS and .js files) on the resque web pages are now broken because the links are not prefaced with resque/. In other words, the link for Working is just /working but it needs to be /resque/working for nginx to know what to do with it.

I've tried other things like getting rid of the rewrite and changing the index page to point to resque/overview but that still gives me the "Sinatra doesn’t know this ditty" page.

I've tried:

location /resque
{
  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;
  proxy_pass http://<%= resque_host.full_name %>:<%= rubber_env.resque_web_port %>;
}

I get the "Sinatra...ditty" page when I hit /resque or /resque/overview.

Then I added the rewrite back in:

location /resque
{
  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;
  rewrite ^/resque/(.*) /$1 break;
  proxy_pass http://<%= resque_host.full_name %>:<%= rubber_env.resque_web_port %>;
}

And this was the same result as not having all the proxy calls.

Does anyone know how to get nginx and the Resque web server working nicely together?

Upvotes: 2

Views: 870

Answers (1)

Nick Messick
Nick Messick

Reputation: 3212

Wow, what a coincidence. I'm working on upgrading our app from Rubber 1.15 -> 2.0.5 and I ran into this problem just yesterday!

Yes, rubber vulcanize resque should take care of this, but apparently no one wrote the Nginx proxy configs.

Your first try at the Nginx was pretty much the correct thing to do.

The reason the CSS, images, and links are broken is because resque-web is looking for all the stuff relative to the root of the resque-web app. What you need to is change the resque-web Rack file (/config/resque-web.ru) to fire up the app in the subdir of /resque. That way everything will be relative (/resque/overview, etc.) and be fine.

I submitted a pull request yesterday to fix this for future users, but you can apply these changes to your project and everything will work for you.

Let me know if that doesn't work.

Upvotes: 3

Related Questions