Skip to content

Instantly share code, notes, and snippets.

@johnthethird
Created March 5, 2010 19:34
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 19 You must be signed in to fork a gist
  • Save johnthethird/323048 to your computer and use it in GitHub Desktop.
Save johnthethird/323048 to your computer and use it in GitHub Desktop.
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;
#server 10.0.1.18:8098;
#server 10.0.1.19:8098;
}
server {
listen 80;
server_name _;
access_log /var/log/nginx/riak.access.log;
# your standard Nginx config for your site here...
location / {
root /var/www/nginx-default;
}
# Expose the /riak endpoint and allow queries for keys only
location /riak/ {
proxy_set_header Host $host;
proxy_redirect off;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 64k; # If the buffers are set to small, nginx will complain about "too large headers"
proxy_buffers 4 64k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
if ($request_method != GET) {
return 405;
}
# Disallow any link with the map/reduce query format "bucket,tag,_"
if ($uri ~ "/riak/[^/]*/[^/]*/[^,]+,[^,]+," ) {
return 405;
}
if ($request_method = GET) {
proxy_pass http://riak_hosts;
}
}
}
@charlesjohnson
Copy link

Thanks for this, it looks really good. There are two things I added: First, I set my server to reply with a 1x1 transparent gif to all requests for favicon.ico, since I don't have them in my apps:

#Serve an empty 1x1 gif for favicon.ico
  location = /favicon.ico {
    empty_gif;
  }

Second, I set max_fails and fail_timeout on each host in the upstream:
server host:port max_fails=3 fail_timeout=30s;

@gigonaut
Copy link

yeah, thanks for this.

@dayanand-sourcebits
Copy link

I did set this up but getting a lot 502/400 errors seems to buffer problem but increasing buffers gives no help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment