Use rewrite /blog to transparently proxy to another app

Hi,

I have various applications running RoR. In order to improve code
maintenability I have decided to use a single blog application that will
be used by different apps.

So a user will be browsing app1 at: app1.com

And when he wants to check out the blog of app1 he goes to:
app1.com/blog which behind the scene transfer the request to my blog
engine.

I tried the following:

server {

location ^~ /blog/ {
proxy_set_header Host $http_host;
proxy_pass http://blog$uri;
}
}

But it seems to ∞ly redirect the request.

Thanks for your upload

Why in hell does it insist on redirecting?

location /blog/ {
rewrite /blog/(.+) $1 break;
proxy_pass http://blog;
}

I never understood how nginx handled rewrites.

Fernando P. wrote:

Why in hell does it insist on redirecting?

location /blog/ {
rewrite /blog/(.+) $1 break;
proxy_pass http://blog;
}

I never understood how nginx handled rewrites.

My bad, it was my trialing slash rewriter that was conflicting. But now
how to handle the trialing slash issue? Just deal with it and hope no
one links to my apps with/without trialing slashes?

Sorry for the typos, trialing should read trailing.

Here is the complete thing for those interested, your mileage may vary
depending how you want the backend app to handle /blog/uri or just /uri

location ^~ /blog/ {
rewrite /blog/(.+) $1 break;
proxy_set_header Host $http_host;
root /optional/root;
proxy_pass http://127.0.0.1:3000/$1;
}

On Mon, Aug 02, 2010 at 10:01:26PM +0200, Fernando P. wrote:

}
location ^~ /blog/ {
proxy_pass http://127.0.0.1:3000/;
proxy_set_header Host $http_host;
}


Igor S.
http://sysoev.ru/en/

How to intercept blog.*?

I tried setting server_name blog.* but it doesn’t seem to work.

Argh! In practice it doesn’t work, as the urls generated by Rails are
incorrect. Therefore I need to use subdomains: blog.* => proxy_pass

I’ll see what I can come up with.

On Tue, Aug 03, 2010 at 08:45:54PM +0200, Fernando P. wrote:

How to intercept blog.*?

I tried setting server_name blog.* but it doesn’t seem to work.

server {
server_name blog.*;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
}
}


Igor S.
http://sysoev.ru/en/

Any reason why server_name blog.; works on my dev machine by only
catching http://blog.
and totally fails on my server by catching
everything?

Fernando P. wrote:

Any reason why server_name blog.; works on my dev machine by only
catching http://blog.
and totally fails on my server by catching
everything?

Update: by setting listen 80 default; to my server that should be
catching all that wasn’t catched previously it appears that server_name
blog.*; isn’t catching anything at all.

I tried setting server_name blog.* but it doesn’t seem to work.

server {
server_name blog.*;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
}
}

My bad, it does work. Thank you Igor.

What the duck?

I switched to Safari, and it works. I was using Firefox, why wouldn’t it
work previously? Is there some caching going on? That’s pita.

I restarted Firefox and I still can’t access my app at
http://blog.example.com

On Thu, Aug 05, 2010 at 01:51:26PM +0200, Fernando P. wrote:

Ok so for some obscure reason, I had to clear my history in Firefox to
make things work.

I still don’t understand why that would perturb Nginx in detecting the
blog’s subdomain.

Sorry, we can diagnose a problem using debug/error log.
We can not diagnose a “it does not work” problem.


Igor S.
http://sysoev.ru/en/

Ok so for some obscure reason, I had to clear my history in Firefox to
make things work.

I still don’t understand why that would perturb Nginx in detecting the
blog’s subdomain.

On Thu, Aug 05, 2010 at 06:31:10PM +0200, Fernando P. wrote:

Sorry, we can diagnose a problem using debug/error log.
We can not diagnose a “it does not work” problem.

What should I be looking for? Specific headers that Firefox was sending?

http://nginx.org/en/docs/debugging_log.html


Igor S.
http://sysoev.ru/en/

Sorry, we can diagnose a problem using debug/error log.
We can not diagnose a “it does not work” problem.

What should I be looking for? Specific headers that Firefox was sending?