Skip to content

Instantly share code, notes, and snippets.

@johnthethird
Created March 5, 2010 19:34
Show Gist options
  • Save johnthethird/323048 to your computer and use it in GitHub Desktop.
Save johnthethird/323048 to your computer and use it in GitHub Desktop.

Revisions

  1. johnthethird created this gist Mar 5, 2010.
    55 changes: 55 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    # 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;
    }
    }
    }