Bioshox
Posts: 104
Joined: Sun May 27, 2012 12:18 pm
Location: Manchester, United Kingdom.
Contact: Website

Reverse Proxy

Tue Aug 28, 2012 2:42 pm

Hi

Could someone tell me what the hell a reverse proxy is?

If I'm right, could I use one raspberry Pi with NGINX running to accesses two other Raspberry Pis running Apache on the same network and serve them up on different ports??

Thanks
Owner of: http://www.fusionstrike.com - I make gorgeous Raspberry Pi Tutorials :)

User avatar
pi3g
Authorised Reseller
Authorised Reseller
Posts: 147
Joined: Mon Nov 05, 2012 9:58 pm
Location: Germany
Contact: Website

Re: Reverse Proxy

Tue Dec 04, 2012 12:14 pm

Hi,

you're right. A reverse proxy sits between a webserver and the webbrowser and is transparent to it. (i.e. the webbrowser thinks it is talking to a webserver directly).

Reverse proxies can be used in manifold ways. Often they are used to accelerate websites or do loadbalancing between several backend servers (which will run PHP / Java / ... ).

For instance my beloved Varnish HTTP Accelerator is a reverse proxy which serves content from its own cache if it is still valid (which is detected by rules you set up for it), if it is invalid, it fetches a fresh content copy from the backend (webserver) and delivers it to the webbrowser connected to itself.

Unfortunately Varnish does not work (yet) on the Raspberry Pi - I've just tried it. I will find a solution for Varnish on Raspberry Pi and post it on my blog, once it is finished.

NGINX can also be used as a reverse proxy. I've already gotten it working using this setup:

/etc/nginx/conf.d/proxy.conf

Code: Select all

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_max_temp_file_size 0;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
/etc/nginx/sites-enabled/raspberry.pi.conf

Code: Select all

 
server {
listen   80 default;
server_name  raspberry.pi;

access_log  /var/log/nginx/raspberry.pi.access.log;

location / {
proxy_pass http://192.168.192.125/;
proxy_redirect default;
}
}
Once you've added the code, you need to restart nginx

192.168.192.125 is my backend here, you should change it to whatever you want.

This is the setup for ONE backend. Of course, more than one backend can be specified for different purposes.

You could also mount paths, i.e. http://yourpi/path_one http://yourpi/path_two to different backends. This is possible with Varnish, and a feature I already use. Great for working around crossdomain request limitations! I think it should be possible with NGINX too.


Other interesting applications for reverse proxies:
  • filter requests by browser / plattform, pass to different backend setups
  • rewrite requests on the fly (less messy than mod_rewrite :-)
  • Block IPs / malicious user agents, ...
  • ... many more.
picockpit.com - tools to make your life with the Pi a little bit easier

Return to “Networking and servers”