Last active
December 6, 2018 12:22
-
-
Save hathaway/5952225 to your computer and use it in GitHub Desktop.
nginx proxy for elasticsearch
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 { | |
listen 8080; | |
server_name elasticsearch; | |
client_max_body_size 50M; | |
error_log /var/log/nginx/elasticsearch-errors.log; | |
access_log /var/log/nginx/elasticsearch.log; | |
location / { | |
# Deny Nodes Shutdown API | |
if ($request_filename ~ "_shutdown") { | |
return 403; | |
break; | |
} | |
# Deny access to Cluster API | |
if ($request_filename ~ "_cluster") { | |
return 403; | |
break; | |
} | |
# Pass requests to ElasticSearch | |
proxy_pass http://localhost:9200; | |
proxy_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
# For CORS Ajax | |
proxy_pass_header Access-Control-Allow-Origin; | |
proxy_pass_header Access-Control-Allow-Methods; | |
proxy_hide_header Access-Control-Allow-Headers; | |
add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type'; | |
add_header Access-Control-Allow-Credentials true; | |
# Authorize access | |
auth_basic "ElasticSearch"; | |
auth_basic_user_file /usr/local/etc/elasticsearch/passwords; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment