Skip to content

Instantly share code, notes, and snippets.

@pierre-b
Created July 9, 2012 21:17
Show Gist options
  • Save pierre-b/3079001 to your computer and use it in GitHub Desktop.
Save pierre-b/3079001 to your computer and use it in GitHub Desktop.
Nginx config elasticsearch _search only
#API usage: feeds.mysite.fr/index/type?q=*
server {
listen 91.191.152.55:443;
server_name feeds.mysite.fr;
access_log /var/log/nginx/elasticsearch.access.log;
error_log /var/log/nginx/elasticsearch.error.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;
}
if ($request_method !~ ^(GET|POST|HEAD)$ ) {
return 405;
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
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
# Route all requests to feeds index
rewrite ^(.*)/(.*)/(.*) /$1/$2/_search$3 break;
rewrite_log on;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment