Easy to set up proxy to protect Solr

3,709 views
Skip to first unread message

Kai Schlamp

unread,
Feb 11, 2011, 10:39:28 AM2/11/11
to ajax-solr
I use Ajax-Solr to query a Solr server on my development machine. But
when I go into production, I guess I have to protect Solr somehow that
only some predefined queries are possible. I guess I have to use a
proxy (the ajax-solr tutorial even says that there is an upcoming
proxy tutorial, is that right?).
Can someone recommend an easy to set up proxy to protect Solr? Maybe
there is already a nice tutorial or blog post somewhere about that
topic.

Best regards,
Kai

Ben Ausden

unread,
Feb 11, 2011, 11:14:34 AM2/11/11
to ajax...@googlegroups.com
We ran a Solr cluster behind an Nginx proxy. Ngnix was configured to only permit GET requests to http://server/solr/select. Worked a treat, and scales extremely well. Nginx is pretty lightweight and consumes virtually no resources even when handling thousands of requests per minute.

e.g.

location /solr/select {
proxy_pass http://YourSolrServer/solr/select;
proxy_buffering on;
}

Check the Nginx docs for more examples. You could achieve the same result with Apache, but for our purposes Nginx scaled better.

Also you might want to let Nginx gzip the json content returned to Ajax-Solr.

Cheers.

James McKinney

unread,
Feb 11, 2011, 11:46:41 AM2/11/11
to ajax...@googlegroups.com
I like Ben's approach. Here is a simple PHP proxy: https://gist.github.com/298580

Kai Schlamp

unread,
Feb 11, 2011, 2:10:16 PM2/11/11
to ajax-solr
Ben, James ... thanks for your recommendations. The app is implemented
in Ruby On Rails. So one solution indeed would be a reverse proxy
using Nginx (which has a very good Ruby support by using Passenger).
And like Ben, I also thought about a little fast Sinatra app in front
of the main Rails app that handles the Solr requests.
I guess the advantage of the first solution is a bit better
performance, but also harder to configure. The second one may be bit
slower, but can contain more logic. On the other side does Nginx also
features a good if statement syntax with regexp checking. Hm, so both
solutions are quite nice ... hard decision.

Ben Ausden

unread,
Feb 11, 2011, 2:23:20 PM2/11/11
to ajax...@googlegroups.com
Personally, I can't see the advantage of writing custom code just to proxy Ajax-Solr requests. More things to maintain, more things to document, more things to break.

Unless you have some really unique requirements to fulfil... ;-)

James McKinney

unread,
Feb 11, 2011, 2:44:55 PM2/11/11
to ajax...@googlegroups.com
On Fri, Feb 11, 2011 at 2:23 PM, Ben Ausden <ben.a...@gmail.com> wrote:
Personally, I can't see the advantage of writing custom code just to proxy Ajax-Solr requests. More things to maintain, more things to document, more things to break.

Unless you have some really unique requirements to fulfil... ;-)

If you just need the Solr response (which is a good way to architect things), then an nginx proxy is best, I think. But I've encountered people who want to intercept the response and augment/filter it with custom code.
Reply all
Reply to author
Forward
0 new messages