-
-
Save simoncpu/bea15e302e9a56c55384 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 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