apiVersion: v1
kind: ConfigMap
metadata:
  name: loki-gateway
  namespace: loki
  labels:
    helm.sh/chart: loki-6.49.0
    app.kubernetes.io/name: loki
    app.kubernetes.io/instance: loki
    app.kubernetes.io/version: "3.6.3"
    app.kubernetes.io/component: gateway
data:
  nginx.conf: "worker_processes  5;  ## Default: 1\nerror_log  /dev/stderr;\npid        /tmp/nginx.pid;\nworker_rlimit_nofile 8192;\n\nevents {\n  worker_connections  4096;  ## Default: 1024\n}\n\nhttp {\n  client_body_temp_path /tmp/client_temp;\n  proxy_temp_path       /tmp/proxy_temp_path;\n  fastcgi_temp_path     /tmp/fastcgi_temp;\n  uwsgi_temp_path       /tmp/uwsgi_temp;\n  scgi_temp_path        /tmp/scgi_temp;\n\n  client_max_body_size  4M;\n\n  proxy_read_timeout    600; ## 10 minutes\n  proxy_send_timeout    600;\n  proxy_connect_timeout 600;\n\n  proxy_http_version    1.1;\n\n  default_type application/octet-stream;\n  log_format   main '$remote_addr - $remote_user [$time_local]  $status '\n        '\"$request\" $body_bytes_sent \"$http_referer\" '\n        '\"$http_user_agent\" \"$http_x_forwarded_for\"';\n  access_log   /dev/stderr  main;\n\n  sendfile     on;\n  tcp_nopush   on;\n  resolver kube-dns.kube-system.svc.cluster.local.;\n\n  # if the X-Query-Tags header is empty, set a noop= without a value as empty values are not logged\n  map $http_x_query_tags $query_tags {\n    \"\"        \"noop=\";            # When header is empty, set noop=\n    default   $http_x_query_tags; # Otherwise, preserve the original value\n  }\n\n  server {\n    listen             8080;\n    listen             [::]:8080;\n\n    location = / {\n      \n      return 200 'OK';\n      auth_basic off;\n    }\n\n    ########################################################\n    # Configure backend targets\n    location ^~ /ui {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # Distributor\n    location = /api/prom/push {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /loki/api/v1/push {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /distributor/ring {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /otlp/v1/logs {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # Ingester\n    location = /flush {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location ^~ /ingester/ {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /ingester {\n      \n      internal;        # to suppress 301\n    }\n\n    # Ring\n    location = /ring {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # MemberListKV\n    location = /memberlist {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # Ruler\n    location = /ruler/ring {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /api/prom/rules {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location ^~ /api/prom/rules/ {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /loki/api/v1/rules {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location ^~ /loki/api/v1/rules/ {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /prometheus/api/v1/alerts {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /prometheus/api/v1/rules {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # Compactor\n    location = /compactor/ring {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /loki/api/v1/delete {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /loki/api/v1/cache/generation_numbers {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # IndexGateway\n    location = /indexgateway/ring {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # QueryScheduler\n    location = /scheduler/ring {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n    # Config\n    location = /config {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n\n\n    # QueryFrontend, Querier\n    location = /api/prom/tail {\n      proxy_set_header Upgrade $http_upgrade;\n      proxy_set_header Connection \"upgrade\";\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /loki/api/v1/tail {\n      proxy_set_header Upgrade $http_upgrade;\n      proxy_set_header Connection \"upgrade\";\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location ^~ /api/prom/ {\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /api/prom {\n      \n      internal;        # to suppress 301\n    }\n    location ^~ /loki/api/v1/ {\n      # pass custom headers set by Grafana as X-Query-Tags which are logged as key/value pairs in metrics.go log messages\n      proxy_set_header X-Query-Tags \"${query_tags},user=${http_x_grafana_user},dashboard_id=${http_x_dashboard_uid},dashboard_title=${http_x_dashboard_title},panel_id=${http_x_panel_id},panel_title=${http_x_panel_title},source_rule_uid=${http_x_rule_uid},rule_name=${http_x_rule_name},rule_folder=${http_x_rule_folder},rule_version=${http_x_rule_version},rule_source=${http_x_rule_source},rule_type=${http_x_rule_type}\";\n      \n      proxy_pass       http://loki.loki.svc.cluster.local:3100$request_uri;\n    }\n    location = /loki/api/v1 {\n      \n      internal;        # to suppress 301\n    }\n  }\n}\n"
