Last active
October 7, 2015 07:26
-
-
Save gansbrest/47c313446bac206c21d5 to your computer and use it in GitHub Desktop.
Use Nginx basic auth to protect HTTP services like Solr ( http://distinctplace.com/howto/2014/07/16/use-nginx-basic-auth-to-protect-http-services-like-solr/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Just an FYI, there's a typo in the config at line 10... missing quote... =)