Observability Azure

Grafana Loki on Windows Server 2025 on Azure User Guide

| Product: Grafana Loki on Windows Server 2025 on Azure

Overview

Grafana Loki is an open source log aggregation system from Grafana Labs. Instead of indexing the full text of every log line, it indexes a small set of labels for each log stream (such as app or level) and stores the lines themselves compressed. That keeps storage small and makes Loki cheap to run. You query it with LogQL, which selects streams by their labels, filters lines and turns them into metrics. Grafana Alloy, Promtail, Fluent Bit, OpenTelemetry collectors and any client that speaks the Loki push API can send it logs, and Grafana reads them back.

This image runs Loki 3.7.11 as a Windows service on Windows Server 2025 Datacenter (Desktop Experience), in single binary mode with its store on the VM's disk. Loki in this mode has no sign-in of its own, so it listens only on the VM itself (127.0.0.1:3100). In front of it, Caddy serves HTTPS on port 443 and asks for a password on every request, and port 80 only redirects to HTTPS. On the first boot of every VM the image creates a random password and a TLS certificate of its own, so nothing is shared between machines and no default password ships. The Windows Server licence is included in the virtual machine price that Microsoft bills; Grafana Loki is open source under the GNU AGPL v3.0. cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.

What is included:

  • Grafana Loki 3.7.11 (upstream's unmodified Windows build) as C:\Program Files\Loki\loki.exe, running as the Windows service Loki (startup Automatic) under its own virtual account NT SERVICE\Loki, not LocalSystem
  • The configuration C:\Program Files\Loki\loki.yaml: one tenant, the HTTP API on 127.0.0.1:3100 and gRPC on 127.0.0.1:9096, the TSDB index (schema v13) and log chunks under C:\ProgramData\Loki, and Loki's anonymous usage reporting turned off
  • Caddy 2.11.9 as the HTTPS front, running as the Windows service LokiProxy (display name Grafana Loki HTTPS (Caddy)) under NT SERVICE\LokiProxy: HTTPS on TCP 443 with this VM's own certificate and password, live tail and long queries passed through as they stream, TCP 80 redirecting to HTTPS, and Windows Firewall rules for both ports
  • A per-VM password for the user admin, written to a file only administrators can read
  • A per-VM self signed TLS certificate for the VM's public IP address, private IP address and computer name
  • Loki's licence (LICENSE-Loki.txt), its LICENSING-Loki.md and a README naming the exact source release, beside the program
  • Windows Server 2025 Datacenter, patched with Windows Update at build, Microsoft Defender Antivirus and Windows Firewall on
  • cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours

Prerequisites

An active Azure subscription, a Remote Desktop client, and a virtual network in the target region.

Standard_B2ms (2 vCPU, 8 GiB RAM) is a good start for a single server taking logs from a handful of machines. Choose a larger size for heavy ingestion or wide queries. Loki keeps its data on the OS disk in C:\ProgramData\Loki, so size the disk for the volume of logs you keep.

In the network security group, allow inbound TCP 3389 (Remote Desktop), TCP 443 (the Loki API over HTTPS) and TCP 80 (the redirect to HTTPS) from your own address ranges only.

Step 1 - Deploy from the Azure Marketplace

Sign in to the Azure Portal, choose Create a resource, search the Marketplace for Grafana Loki on Windows Server 2025 by cloudimg, and select Create. On Basics pick your subscription, resource group, region and size, and set the Administrator account username and password. Under Inbound port rules allow RDP (3389), HTTP (80) and HTTPS (443), then narrow each rule's source to your own address range on the Networking tab. Select Review + create, then Create.

Step 2 - Deploy from the Azure CLI

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn cloudimg1647283583153:loki-windows-server:default:latest

az vm create \
  --resource-group <your-rg> \
  --name loki \
  --image cloudimg1647283583153:loki-windows-server:default:latest \
  --size Standard_B2ms \
  --admin-username <admin-name> \
  --admin-password '<a strong password>' \
  --public-ip-sku Standard

az vm open-port --resource-group <your-rg> --name loki --port 3389 --priority 1000
az vm open-port --resource-group <your-rg> --name loki --port 443 --priority 1010
az vm open-port --resource-group <your-rg> --name loki --port 80 --priority 1020

az vm open-port opens each port to any address; narrow the rules to your own ranges in the network security group afterwards.

First boot takes a few minutes. When the VM first starts, Windows finishes its setup. Then the image creates this VM's password, certificate and configuration and starts both services. Until then nothing answers on port 443. The setup is finished when the file C:\ProgramData\loki-windows-server-firstboot.done exists (Step 4).

Step 3 - Connect with Remote Desktop

Connect to the VM's public IP address with your Remote Desktop client (on Windows, mstsc; on macOS, Windows App), signing in with the administrator name and password you set at deployment. Open Windows PowerShell as administrator for the commands below.

Step 4 - Confirm Loki is running

Test-Path C:\ProgramData\loki-windows-server-firstboot.done
Get-CimInstance Win32_Service -Filter "Name LIKE 'Loki%'" | Format-Table Name, State, StartMode, StartName -AutoSize
Get-NetTCPConnection -State Listen -LocalPort 443, 80, 3100, 9096 | Sort-Object LocalPort | Format-Table LocalAddress, LocalPort, @{n='Process';e={(Get-Process -Id $_.OwningProcess).ProcessName}} -AutoSize
Invoke-RestMethod http://127.0.0.1:3100/ready
& 'C:\Program Files\Loki\loki.exe' --version
True

Name      State   StartMode StartName
----      -----   --------- ---------
Loki      Running Auto      NT SERVICE\Loki
LokiProxy Running Auto      NT SERVICE\LokiProxy

LocalAddress LocalPort Process
------------ --------- -------
::                  80 caddy
::                 443 caddy
127.0.0.1         3100 loki
127.0.0.1         9096 loki

ready

loki, version 3.7.11 (branch: release-3.7.x, revision: 56f8c86a)
  build user:       root@e08f4a1011a9
  build date:       2026-11-27T13:38:57Z
  go version:       go1.26.10
  platform:         windows/amd64
  tags:             netgo

An elevated PowerShell window on a new VM: the Loki and LokiProxy services running as their own accounts and starting automatically, Caddy on ports 80 and 443, Loki on 127.0.0.1:3100 and 9096 only, Loki ready, and loki.exe reporting version 3.7.11

True confirms first boot finished. Both services run under their own accounts and start automatically with Windows. Only Caddy listens on the network (ports 443 and 80). Loki itself listens on 127.0.0.1, which nothing outside the VM can reach, so every request from outside passes the password check first. Loki answers ready once it can take logs; for about 15 seconds after each start it answers Ingester not ready instead.

The first boot log records what it made (the addresses are this VM's own, shown here as placeholders):

Get-Content C:\ProgramData\loki-windows-server-firstboot.log
2026-12-03T10:39:52.0081554Z provisioning finished
2026-12-03T10:39:57.5816527Z addresses public=<public-address> private=<private-address>
2026-12-03T10:39:59.3256360Z certificate CN=<public-address> names=<computer-name>,<public-address>,<private-address> sha256=830ecc1616935188638ce45beec509bb4680d53a49975afcd4453c504f56465d
2026-12-03T10:40:15.4661815Z certificate, key and Caddyfile written
2026-12-03T10:40:15.5513860Z credentials written
2026-12-03T10:42:18.4740457Z Loki is ready on 127.0.0.1:3100; HTTPS on 443 asks for the password; 80 listens
2026-12-03T10:42:28.5990825Z first boot done

The certificate is named for the VM's public IP address, its private IP address and its computer name, and is valid for ten years. Its public half is C:\ProgramData\LokiProxy\tls\cert.pem.

Step 5 - Read your password

First boot wrote the user name and password to a file that only the SYSTEM account and the Administrators group can read:

Get-Content C:\ProgramData\loki-windows-server-credentials.txt
# Grafana Loki on Windows Server 2025 by cloudimg: this VM's own sign-in for the Loki API (made at first boot).
# Push to and query https://<this VM's public IP>/loki/api/v1/... (port 80 redirects there) with HTTP Basic auth: the user and password below.
# The certificate is this VM's own, self-signed: its public half is C:\ProgramData\LokiProxy\tls\cert.pem.
# Guide: https://www.cloudimg.co.uk/guides/grafana-loki-on-windows-server-2025-azure/

loki-windows-server.admin.user=admin
loki-windows-server.admin.password=<24 random characters, different on every VM>

The user name is always admin; the password is random and different on every VM. Keep it somewhere safe and share it only with the people, log shippers and Grafana servers that should use the API.

An elevated PowerShell window: the credentials file readable by SYSTEM and Administrators only, and its contents with the password hidden

Step 6 - Check the API

Every request goes through HTTPS with the user name and password. This is a session on the VM itself, in PowerShell, with curl.exe (part of Windows). -k is needed because the certificate is the VM's own self signed one. The password is read into a variable and never shown:

PS> $pw = ((Get-Content C:\ProgramData\loki-windows-server-credentials.txt) -match 'password=') -replace '^[^=]+=', ''

PS> curl.exe -sk -o NUL -w "no password: HTTP %{http_code}`n" https://127.0.0.1/loki/api/v1/labels
no password: HTTP 401

PS> curl.exe -sk -u "admin:$pw" https://127.0.0.1/ready
ready

PS> curl.exe -sk -u "admin:$pw" https://127.0.0.1/loki/api/v1/status/buildinfo
{"version":"3.7.11","revision":"56f8c86a","branch":"release-3.7.x","buildUser":"root@e08f4a1011a9","buildDate":"2026-11-27T13:38:57Z","goVersion":""}

Without the password every path answers 401. With it, Loki says it is ready and reports its version:

PowerShell on the server: the Loki services running, Loki ready and its build info (3.7.11), read through HTTPS with the VM's password

Step 7 - Push logs and read them back

Loki takes logs at POST /loki/api/v1/push: a JSON body of streams, each with its labels and its lines, each line with a timestamp in nanoseconds. Windows PowerShell 5.1 changes double quotes on the way to curl.exe, so the body goes in a file and --data-binary "@file" sends it unchanged. This pushes two info lines and one error line for an app called shop, then reads every shop line back with the LogQL stream selector {app="shop"}:

PS> $t = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() * 1000000

PS> '{"streams":[{"stream":{"app":"shop","level":"info"},"values":[["' + $t + '","order 1001 paid"],["' + ($t + 1000000) + '","order 1002 paid"]]},{"stream":{"app":"shop","level":"error"},"values":[["' + ($t + 2000000) + '","payment timeout for order 1003"]]}]}' | Set-Content push.json -Encoding ascii

PS> curl.exe -sk -u "admin:$pw" -H "Content-Type: application/json" --data-binary "@push.json" -w "push: HTTP %{http_code}`n" https://127.0.0.1/loki/api/v1/push
push: HTTP 204

PS> $r = curl.exe -sk -u "admin:$pw" -G --data-urlencode 'query={app=\"shop\"}' https://127.0.0.1/loki/api/v1/query_range | ConvertFrom-Json

PS> $r.data.result | ForEach-Object { $l = $_.stream.level; $_.values | ForEach-Object { [pscustomobject]@{ time = [DateTimeOffset]::FromUnixTimeMilliseconds([long]$_[0].Substring(0, 13)).ToString('HH:mm:ss.fff'); level = $l; line = $_[1] } } } | Sort-Object time | Format-Table -AutoSize

time         level line
----         ----- ----
10:44:22.028 info  order 1001 paid
10:44:22.029 info  order 1002 paid
10:44:22.030 error payment timeout for order 1003

204 means Loki took the lines. query_range looks back one hour unless you give start and end. In a LogQL query sent through curl.exe from Windows PowerShell 5.1, write each double quote inside the query as \", as above.

Three log lines pushed through the HTTPS front (HTTP 204) and read back with the LogQL selector {app="shop"}

Loki keeps every line it is sent, each with its own timestamp. Pushing the same three lines again five minutes later and running the same query returns both sends:

The same three lines pushed a second time, five minutes later: the query returns all six, each with its own timestamp

Step 8 - Query with LogQL

Loki lists the labels it has indexed and each label's values. A LogQL metric query turns lines into numbers, here the lines per level over the last hour, and a line filter (|=) keeps only the lines that contain a word. This was run after the single push in Step 7:

PS> curl.exe -sk -u "admin:$pw" https://127.0.0.1/loki/api/v1/labels
{"status":"success","data":["app","level","service_name"]}

PS> curl.exe -sk -u "admin:$pw" https://127.0.0.1/loki/api/v1/label/level/values
{"status":"success","data":["error","info"]}

PS> (curl.exe -sk -u "admin:$pw" -G --data-urlencode 'query=sum by (level) (count_over_time({app=\"shop\"}[1h]))' https://127.0.0.1/loki/api/v1/query | ConvertFrom-Json).data.result | Format-Table @{n='level';e={$_.metric.level}}, @{n='lines in the last hour';e={$_.value[1]}} -AutoSize

level lines in the last hour
----- ----------------------
error 1
info  2

PS> (curl.exe -sk -u "admin:$pw" -G --data-urlencode 'query={app=\"shop\"} |= \"timeout\"' https://127.0.0.1/loki/api/v1/query_range | ConvertFrom-Json).data.result | ForEach-Object { $_.values | ForEach-Object { $_[1] } }
payment timeout for order 1003

Loki adds the label service_name itself, from the stream's other labels, when a push does not set it.

LogQL through the HTTPS front: the labels, the values of level, lines counted per level and a line filter for "timeout"

Step 9 - Connect Grafana and your log shippers

From other machines, use https://<vm-public-ip>/ in place of https://127.0.0.1/, with the user admin and the VM's password as HTTP Basic authentication. For example, from macOS or Linux: curl -k -u "admin:<password>" https://<vm-public-ip>/loki/api/v1/labels.

  • Grafana: add a Loki data source with the URL https://<vm-public-ip>. Under Authentication choose Basic authentication with admin and the password. For the TLS settings, either add the VM's certificate (C:\ProgramData\LokiProxy\tls\cert.pem) as a self-signed certificate, or install a trusted certificate on the VM (see Use a DNS name and a trusted certificate below). Then Save & test.
  • Log shippers (Grafana Alloy, Promtail, Fluent Bit and other clients of the Loki push API): set the push URL to https://<vm-public-ip>/loki/api/v1/push, Basic authentication to admin and the password, and trust the VM's certificate the same way.

Push requests are limited to 64 MB each through the HTTPS front; shippers send far smaller batches.

How the API is protected

PS> curl.exe -sk -o NUL -w "with the password: HTTP %{http_code}`n" -u "admin:$pw" https://127.0.0.1/loki/api/v1/labels
with the password: HTTP 200

PS> curl.exe -sk -o NUL -w "push from another site's page: HTTP %{http_code}`n" -u "admin:$pw" -H "Origin: https://example.com" -H "Content-Type: application/json" --data "{}" https://127.0.0.1/loki/api/v1/push
push from another site's page: HTTP 403

401 without the password, 200 with it, 403 for a push from another site's page, Loki on loopback only with Caddy on 80 and 443, and the two inbound firewall rules

Caddy checks the password before passing a request on, and removes the Authorization header so Loki never sees the password. A request that would change data (a push or a delete) is refused with 403 when it carries another website's Origin header, so a web page open in a browser that has the password cannot write to Loki. Log shippers and Grafana do not send that header and are not affected. Loki listens only on 127.0.0.1. Windows Firewall allows 443 and 80 through the two rules in the Loki group; the network security group decides who can reach them.

Change the password

The password is checked by Caddy, which keeps only a bcrypt hash of it in C:\ProgramData\LokiProxy\Caddyfile. To change it, open an administrator PowerShell, make the hash of your new password, put it in place of the old hash on the admin line of the Caddyfile, and restart the front:

& 'C:\Program Files\Loki\caddy\caddy.exe' hash-password --plaintext '<new password>'
notepad C:\ProgramData\LokiProxy\Caddyfile      # basic_auth { admin <the new hash> }
Restart-Service LokiProxy

Update the password in C:\ProgramData\loki-windows-server-credentials.txt too, so the file stays right, and in every shipper and Grafana data source that uses it. To give each shipper its own password, add one <name> <hash> line per user inside basic_auth.

Use a DNS name and a trusted certificate

The image's certificate is self signed and named for the VM's IP addresses and computer name. To use a DNS name with a certificate your clients already trust:

  1. Point the name at the VM's public IP.
  2. Get a certificate and key for that name as PEM files.
  3. Replace C:\ProgramData\LokiProxy\tls\cert.pem with the certificate, followed by any intermediate certificates.
  4. Replace key.pem in the same folder with the private key.
  5. Run Restart-Service LokiProxy.

Maintenance

  • Windows updates: Windows Update is on, as Microsoft ships it. Restarting the VM restarts both services automatically.
  • Configuration: Loki reads C:\Program Files\Loki\loki.yaml at start. After a change, run Restart-Service Loki -Force; Start-Service LokiProxy (stopping Loki stops the front too, because the front depends on it). The settings are described in Grafana's Loki configuration reference.
  • How long logs are kept: as shipped, Loki keeps every line until you delete it; retention is off. To delete old logs automatically, turn on retention in the compactor and set a retention period in loki.yaml, as Grafana's retention documentation describes, and watch the free space on the disk.
  • Back up your data: Loki keeps its index, chunks and write-ahead log in C:\ProgramData\Loki. The front keeps its Caddyfile and certificate in C:\ProgramData\LokiProxy. Back up both folders with the services stopped, or use Azure Backup of the VM.
  • Upgrade Loki: you choose when to upgrade.
  • Download loki-windows-amd64.exe.zip of the version you want from the project's GitHub releases, and read its release notes.
  • In an administrator PowerShell, stop the services: Stop-Service LokiProxy, Loki.
  • Replace C:\Program Files\Loki\loki.exe with the loki-windows-amd64.exe from the zip, renamed to loki.exe.
  • Start them again: Start-Service Loki, LokiProxy.

Your logs are kept. - Logs of the services: Loki's own log is in C:\ProgramData\Loki\service-logs and Caddy's in C:\ProgramData\LokiProxy\logs. The first boot log is C:\ProgramData\loki-windows-server-firstboot.log; it never contains the password. - Source code: Loki is licensed under the GNU AGPL v3.0. C:\Program Files\Loki\README.txt names the release the program was built from, and its complete source is at github.com/grafana/loki.

Support

cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours. Contact support@cloudimg.co.uk.