Skip to content

Instantly share code, notes, and snippets.

@simoncpu
Forked from gansbrest/gist:47c313446bac206c21d5
Last active October 7, 2015 07:20
Show Gist options
  • Save simoncpu/bea15e302e9a56c55384 to your computer and use it in GitHub Desktop.
Save simoncpu/bea15e302e9a56c55384 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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment