# Generate password with eg. # # $ printf "john:$(openssl passwd -crypt s3cr3t)\n" > passwords # # Run: # # $ nginx -p $PWD/nginx/ -c $PWD/nginx_http_auth_allow_path_and_method.conf # events { worker_connections 1024; } http { upstream elasticsearch { server 127.0.0.1:9200; } server { listen 8080; location / { error_page 590 = @elasticsearch; error_page 595 = @protected_elasticsearch; set $ok 0; if ($request_uri ~ ^/$) { set $ok "${ok}1"; } if ($request_method = HEAD) { set $ok "${ok}2"; } if ($ok = 012) { return 590; } return 595; } location @elasticsearch { proxy_pass http://elasticsearch; proxy_redirect off; } location @protected_elasticsearch { auth_basic "Protected Elasticsearch"; auth_basic_user_file passwords; proxy_pass http://elasticsearch; proxy_redirect off; } } }