Skip to content

Instantly share code, notes, and snippets.

@polarnik
Created May 3, 2024 07:11
Show Gist options
  • Save polarnik/cb6f22751e8d1590342198609243c529 to your computer and use it in GitHub Desktop.
Save polarnik/cb6f22751e8d1590342198609243c529 to your computer and use it in GitHub Desktop.
NGinx for InfluxDB 2 and VictoriaMetrics
#user nobody
worker_processes 4;
error_log /var/log/nginx/error.log warn;
events {
worker_connections 1024;
}
http {
proxy_cache_path /data/nginx/cache keys_zone=mycache:20m max_size=1g inactive=60m;
limit_conn_zone $server_name zone=perserver:10m;
upstream backend {
server host.docker.internal:8086;
keepalive 5000;
}
upstream victoria_metrics_1 {
server victoria-metrics-1:8428;
keepalive 5000;
}
upstream victoria_metrics_2 {
server victoria-metrics-2:8428;
keepalive 5000;
}
server {
listen 8096;
client_max_body_size 20m;
location /query {
proxy_cache mycache;
proxy_cache_key "$host$request_uri";
proxy_cache_min_uses 1;
proxy_cache_methods GET;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_background_update on;
proxy_cache_revalidate on;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;
proxy_ignore_headers Cache-Control;
proxy_hide_header 'Access-Control-Allow-Origin';
if ($http_origin = ''){
set $http_origin "*";
}
if ($request_method = 'OPTIONS') {
#proxy_hide_header 'Access-Control-Allow-Origin';
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'Pragma,Accept,Authorization,Content-Type,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
#
# Tell client that this pre-flight info is valid for 20 days
#
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
add_header 'Access-Control-Allow-Credentials' 'true';
return 204;
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Pragma,Accept,Authorization,Content-Type,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
proxy_pass http://backend;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Pragma,Accept,Authorization,Content-Type,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
proxy_pass http://backend;
}
}
location = /write1 {
internal;
proxy_pass http://victoria_metrics_1$request_uri;
}
location = /write2 {
internal;
proxy_pass http://victoria_metrics_2$request_uri;
}
location /write {
mirror /write1;
mirror /write2;
proxy_pass http://backend;
}
location / {
proxy_pass http://backend;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment