Skip to content

Instantly share code, notes, and snippets.

@Battleroid
Created September 3, 2019 15:55
Show Gist options
  • Save Battleroid/ca19e1c59449ff2bc30130aacb1c26b5 to your computer and use it in GitHub Desktop.
Save Battleroid/ca19e1c59449ff2bc30130aacb1c26b5 to your computer and use it in GitHub Desktop.
user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
proxy_cache_path /tmp/nginx levels=1:2 keys_zone=cache:10m max_size=1g inactive=24h use_temp_path=off;
proxy_buffer_size 128k;
proxy_buffers 8 256k;
proxy_busy_buffers_size 256k;
client_max_body_size 100M;
client_header_buffer_size 5120k;
large_client_header_buffers 16 5120k;
log_format standard_json '{ "time": "$time_local", "remote_addr": "$remote_addr", "http_x_forwarded_for": "$http_x_forwarded_for", "vhost": "$server_name", "remote_user": "$remote_user", "scheme": "$scheme", "sslinfo": "$ssl_protocol/$ssl_cipher", "request": "$request", "status": "$status", "body_bytes_sent": "$body_bytes_sent", "request_length": "$request_length", "request_time": "$request_time", "http_referer": "$http_referer", "http_user_agent": "$http_user_agent" }';
access_log /dev/stdout standard_json;
error_log /dev/stdout;
upstream kibana {
server 127.0.0.1:5601;
}
# Should force mappings request to include fields=title
server {
listen 8080 default_server;
# general proxy cache settings
proxy_cache cache;
proxy_cache_methods GET;
proxy_cache_lock on;
# have nginx cache static assets
location ~* \.(jpeg|jpg|png|css|js|woff2|svg)$ {
expires 1h;
add_header cache-control "public";
proxy_cache_valid 200 1h;
proxy_cache_use_stale error updating timeout http_503 http_502 http_504 http_500;
proxy_ignore_headers cache-control;
proxy_hide_header cache-control;
more_set_headers "X-Cache-Status: $upstream_cache_status";
more_clear_input_headers "cache-control";
proxy_pass http://kibana;
}
# pain ahead, makes index-patterns only return titles also cached
# could try the expires/cache-control=public ordeal here
location /api/saved_objects/_find {
expires 1m;
set_by_lua_block $skip_cache {
local args = ngx.req.get_uri_args()
if args["type"] == "index-pattern" then
args.fields = "title"
ngx.req.set_uri_args(args)
else
return "true"
end
}
proxy_cache_bypass $skip_cache;
proxy_cache_valid 200 1m;
proxy_cache_use_stale updating timeout http_503 http_502 http_504 http_500;
proxy_pass http://kibana;
more_clear_input_headers "cache-control";
proxy_ignore_headers cache-control;
proxy_hide_header cache-control;
more_set_headers "X-Cache-Status: $upstream_cache_status" "X-Skip-Cache: $skip_cache";
}
location / {
proxy_pass http://kibana;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment