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.
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).
location /api/ {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
}
curl -i -sS -H 'Authorization: Bearer YOUR_TOKEN' https://api.example.com/v1/me
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.
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.
RFC 9110 requires a `WWW-Authenticate` header (e.g. `WWW-Authenticate: Bearer realm="api"`) on 401 responses.