HTTP 401 · 4XX RFC 9110 §15.5.2 Cacheable: No Retryable: After refreshing credentials

HTTP 401 Unauthorized: Root Causes & Production Fix Guide

HTTP 401 Unauthorized indicates missing, expired, or invalid authentication credentials. Despite the name, 401 is about authentication (who you are), whereas 403 is about authorization (what you can do).

Top Root Causes of HTTP 401

Nginx Forward Authorization Header & Emit WWW-Authenticate

location /api/ {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Authorization $http_authorization;
    proxy_pass_header Authorization;
}

Verify with cURL

curl -i -sS -H 'Authorization: Bearer YOUR_TOKEN' https://api.example.com/v1/me

Interactive Stack Diagnoser (HTTP 401)

Frequently Asked Questions

What is the difference between 401 Unauthorized and 403 Forbidden?

401 means the client is not authenticated (missing/invalid token or session). 403 means the server knows who you are, but your role or IP lacks permission.

Why does my browser request return 401 even though curl works?

Cross-origin browser requests do not send cookies unless `credentials: 'include'` is set on fetch AND the server sets `Access-Control-Allow-Credentials: true` with an explicit origin.

Is WWW-Authenticate required on 401 responses?

RFC 9110 requires a `WWW-Authenticate` header (e.g. `WWW-Authenticate: Bearer realm="api"`) on 401 responses.

Related Status Guides & Header Tools