Skip to content

Instantly share code, notes, and snippets.

@gansbrest
Last active October 7, 2015 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gansbrest/47c313446bac206c21d5 to your computer and use it in GitHub Desktop.
Save gansbrest/47c313446bac206c21d5 to your computer and use it in GitHub Desktop.
server
{
# To avoid changing your app config
# point Nginx to the Solr port
listen 8983;
# Set read/write variables
set $solr_write "0";
set $solr_read "1";
set $solr_admin "0;
# Define users permissions
# $remote_user translates to Basic Auth user
if ($remote_user = "solr_r") {
set $solr_write "0";
set $solr_read "1";
}
if ($remote_user = "solr_w") {
set $solr_write "1";
set $solr_read "0";
}
if ($remote_user = "solr_rw") {
set $solr_write "1";
set $solr_read "1";
set $solr_admin "1";
}
# Force Basic Auth for all requests to Solr
# IMPORTANT:
# Make sure to add new users to htpasswd!
auth_basic "Private Beta";
auth_basic_user_file /etc/nginx/conf/htpasswd;
# Write Solr enpoint
location ~* /solr/\w+/update {
if ($solr_write != "1") {
return 403;
}
proxy_pass http://localhost:8900; # Proxy to solr
}
# Read Solr endpoint
location ~* /solr/\w+/select {
if ($solr_read != "1") {
return 403;
}
proxy_pass http://localhost:8900;
}
# Admin UI
location ~* /solr {
if ($solr_admin != "1") {
return 403;
}
proxy_pass http://localhost:8900;
}
# Disable proxy buffering because it was causing problems
proxy_buffering off;
# All other urls expect admin permission
location / {
proxy_pass http://localhost:8900;
}
}
@simoncpu
Copy link

simoncpu commented Oct 7, 2015

Just an FYI, there's a typo in the config at line 10... missing quote... =)

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