I''m using a cluster of mongrels behind an apache 1.3 proxy pass. I''ve been passing the request to pen, which in turn balances the cluster of mongrels. Now, I''d like to be able to use a different server to send the static files created by the rails application, so I tried to replace pen with nginx. Everything seems to work fine except the environment variable REMOTE_ADDR. When I do a <%= request.env["REMOTE_ADDR"] %> with pen balancing, it sends in the proper (and expected) 192.168.1.21. When nginx is the balancer, the output becomes: 192.168.1.21, 127.0.0.1. the nginx proxy information I have set is: proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; Just wondering if anyone else has run into this problem, and it''s possible solution. Thank you.
On Mit 01.11.2006 10:26, Joey Geiger wrote:>I''m using a cluster of mongrels behind an apache 1.3 proxy pass. I''ve >been passing the request to pen, which in turn balances the cluster of >mongrels. Now, I''d like to be able to use a different server to send >the static files created by the rails application, so I tried to >replace pen with nginx. Everything seems to work fine except the >environment variable REMOTE_ADDR.I think this isn''t a mongrel issue.>When I do a <%= request.env["REMOTE_ADDR"] %> with pen balancing, it >sends in the proper (and expected) 192.168.1.21. > >When nginx is the balancer, the output becomes: 192.168.1.21, 127.0.0.1. > >the nginx proxy information I have set is: > >proxy_redirect off; >proxy_set_header Host $host; >proxy_set_header X-Real-IP $remote_addr; >proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;What do you get when you add this line: proxy_set_header REMOTE_ADDR $remote_addr; More about the proxy module can you find here: http://wiki.codemongers.com/NginxHttpProxyModule>Just wondering if anyone else has run into this problem, and it''s >possible solution.How about to ask this on nginx list, I think it *could* be the better list ;-) Regards Aleks
On Wed, 1 Nov 2006 10:26:43 -0600 "Joey Geiger" <jgeiger at gmail.com> wrote:> When I do a <%= request.env["REMOTE_ADDR"] %> with pen balancing, it > sends in the proper (and expected) 192.168.1.21. > > When nginx is the balancer, the output becomes: 192.168.1.21, 127.0.0.1.That''s odd. I wonder if nginx is doing this as a "feature" so you know that it''s really 127.0.0.1 and the other IP. I kind of like that actually. What you can do is turn on -B logging, then go look at log/mongrel_debug/rails.log to see what is being passed to rails. That''ll let you know if it''s getting combined and where. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://safari.oreilly.com/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.
I was able to figure it out after some file editing. I might be a special case because I''m proxying to nginx, which in turn proxies to mongrel. I removed the and only the normal IP was passed. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; On 11/1/06, Aleksandar Lazic <al-mongrelusers at none.at> wrote:> On Mit 01.11.2006 10:26, Joey Geiger wrote: > >I''m using a cluster of mongrels behind an apache 1.3 proxy pass. I''ve > >been passing the request to pen, which in turn balances the cluster of > >mongrels. Now, I''d like to be able to use a different server to send > >the static files created by the rails application, so I tried to > >replace pen with nginx. Everything seems to work fine except the > >environment variable REMOTE_ADDR. > > I think this isn''t a mongrel issue. > > >When I do a <%= request.env["REMOTE_ADDR"] %> with pen balancing, it > >sends in the proper (and expected) 192.168.1.21. > > > >When nginx is the balancer, the output becomes: 192.168.1.21, 127.0.0.1. > > > >the nginx proxy information I have set is: > > > >proxy_redirect off; > >proxy_set_header Host $host; > >proxy_set_header X-Real-IP $remote_addr; > >proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > > What do you get when you add this line: > > proxy_set_header REMOTE_ADDR $remote_addr; > > More about the proxy module can you find here: > > http://wiki.codemongers.com/NginxHttpProxyModule > > >Just wondering if anyone else has run into this problem, and it''s > >possible solution. > > How about to ask this on nginx list, I think it *could* be the better > list ;-) > > Regards > > Aleks > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >
On 11/1/06, Joey Geiger <jgeiger at gmail.com> wrote:> > I''m using a cluster of mongrels behind an apache 1.3 proxy pass. I''ve > been passing the request to pen, which in turn balances the cluster of > mongrels. Now, I''d like to be able to use a different server to send > the static files created by the rails application, so I tried to > replace pen with nginx. Everything seems to work fine except the > environment variable REMOTE_ADDR. > > When I do a <%= request.env["REMOTE_ADDR"] %> with pen balancing, it > sends in the proper (and expected) 192.168.1.21. > > When nginx is the balancer, the output becomes: 192.168.1.21, 127.0.0.1. > > the nginx proxy information I have set is: > > proxy_redirect off; > proxy_set_header Host $host; > proxy_set_header X-Real-IP $remote_addr; > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > > Just wondering if anyone else has run into this problem, and it''s > possible solution.Use request.remote_ip which also understands the proxy headers. jeremy -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20061101/d06d993d/attachment.html
On Mit 01.11.2006 15:02, Joey Geiger wrote:> >I removed the and only the normal IP was passed.^^? Aehm what have you removed?! Regards Aleks
Whoops, I removed the line below. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; I believe what was happening, was that apache was proxying the request to nginx, and adding the x_forwarded_for as the real ip (192.168.1.21) then, nginx was passing the proxy request to mongrel, and was adding the ip that it was forwarding for (127.0.0.1) so the address that was passed to REMOTE_ADDR ended up as 192.168.1.21, 127.0.0.1. By removing that line from the nginx configuration, it only passed the first ip address. On 11/1/06, Aleksandar Lazic <al-mongrelusers at none.at> wrote:> On Mit 01.11.2006 15:02, Joey Geiger wrote: > > > >I removed the and only the normal IP was passed. > ^^? > Aehm what have you removed?! > > Regards > > Aleks > > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >
On Thu, 2 Nov 2006 08:25:41 -0600 "Joey Geiger" <jgeiger at gmail.com> wrote:> Whoops, > I removed the line below. > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > > I believe what was happening, was that apache was proxying the request > to nginx, and adding the x_forwarded_for as the real ip (192.168.1.21) > then, nginx was passing the proxy request to mongrel, and was adding > the ip that it was forwarding for (127.0.0.1) so the address that was > passed to REMOTE_ADDR ended up as 192.168.1.21, 127.0.0.1.Uh, why do you have apache->nginx->mongrel when you can just do nginx->mongrel instead? -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://safari.oreilly.com/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.
The site I work on was build about 7 years ago, using apache 1.3 and mod_perl. The majority of the site still exists in that format. I need to maintain the current apache 1.3edness and attempt to add new functionality using rails. I have http://site.com/app proxying to 127.0.0.1:8000/app (which is nginx) which in turn proxies to mongel listening at prefix=/app. It''s a big mess, especially since I can''t share the image files from the old site that the new rails code needs to use (no sense copying them to public, which is where config.action_controller.asset_host comes in, though it has issues with running under a prefix...) I switched from pen as the balancer to nginx because i believe that mongrel was going to be serving static files created by rails, so I wanted something in front of it that could handle that and pass the static file back to the apache proxy. It all seems to be working right now, fingers crossed. :) On 11/2/06, Zed A. Shaw <zedshaw at zedshaw.com> wrote:> On Thu, 2 Nov 2006 08:25:41 -0600 > "Joey Geiger" <jgeiger at gmail.com> wrote: > > > Whoops, > > I removed the line below. > > proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; > > > > I believe what was happening, was that apache was proxying the request > > to nginx, and adding the x_forwarded_for as the real ip (192.168.1.21) > > then, nginx was passing the proxy request to mongrel, and was adding > > the ip that it was forwarding for (127.0.0.1) so the address that was > > passed to REMOTE_ADDR ended up as 192.168.1.21, 127.0.0.1. > > Uh, why do you have apache->nginx->mongrel when you can just do nginx->mongrel instead? > > -- > Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu > http://www.zedshaw.com/ > http://safari.oreilly.com/0321483502 -- The Mongrel Book > http://mongrel.rubyforge.org/ > http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help. > _______________________________________________ > Mongrel-users mailing list > Mongrel-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mongrel-users >