Reverse Proxy / VPS · location ^~ /.well-known/

Nginx location /.well-known/ JSON MIME, CORS & Caching Config

Hardened Nginx location ^~ /.well-known/ configuration forcing application/json on extensionless RFC 9728/8414 endpoints, always headers, CORS preflight, and isolation from SPA try_files.

Manifest Parameters

Zero Telemetry · Strict CSP
Authentication & OAuth Scopes
RFC 9728 Protected Resource Metadata Options
Exact Well-Known Endpoint URL application/json
https://agent.example.com/.well-known/oauth-protected-resource
/.well-known/oauth-protected-resource
{
  "resource": "https://agent.example.com/mcp",
  "authorization_servers": [
    "https://auth.example.com"
  ],
  "scopes_supported": [
    "agent:invoke",
    "mcp:tools",
    "mcp:read"
  ],
  "bearer_methods_supported": [
    "header"
  ],
  "resource_name": "Acme Cloud Assistant",
  "resource_documentation": "https://docs.example.com/agents"
}
curl Verification Command
curl -i "https://agent.example.com/mcp"
curl -fsSL "https://agent.example.com/.well-known/oauth-protected-resource" | jq .
curl -fsSL "https://auth.example.com/.well-known/oauth-authorization-server" | jq .
HTTP 401 WWW-Authenticate Header (RFC 9728 / MCP-PRO-002)
WWW-Authenticate: Bearer resource_metadata="https://agent.example.com/.well-known/oauth-protected-resource", scope="agent:invoke mcp:tools mcp:read"
Live Well-Known Audit 98.4% Lack Agent Cards

Verify live A2A, MCP, OAuth & AEO discovery in production

In RungLab's N=140 B2B SaaS Readiness Benchmark, 98.4% (62/63) of full-telemetry domains lacked agent-card.json. Audit your live domain with ReadyCheck, cut MCP schema token tax with MCPDiet, or automate fleet discovery checks via Apify & RapidAPI.

Required Endpoints, Paths & MIME Types

Path / Endpoint Purpose Required Content-Type
/etc/nginx/snippets/agent-discovery.conf Included inside your HTTPS server {} block for /.well-known/ agent manifests application/json; charset=utf-8

Hardened Nginx location ^~ /.well-known/ Block

agent-discovery.conf
# Include inside your HTTPS server { ... } block
location ^~ /.well-known/ {
  alias /var/www/discovery/.well-known/;
  default_type application/json;
  charset utf-8;

  # WARNING: Any add_header inside location {} overrides parent server {} add_header rules!
  # Re-include your baseline security headers snippet here if needed:
  # include /etc/nginx/snippets/security-headers.conf;

  add_header Content-Type "application/json; charset=utf-8" always;
  add_header Access-Control-Allow-Origin "*" always;
  add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
  add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;
  add_header Cache-Control "public, max-age=300" always;
  add_header X-Content-Type-Options "nosniff" always;

  if ($request_method = OPTIONS) {
    return 204;
  }

  try_files $uri =404;
}

Validate Nginx Syntax & Test Discovery Endpoints

test-nginx.sh
sudo nginx -t && sudo systemctl reload nginx
curl -i -X OPTIONS "https://yourdomain.com/.well-known/agent-card.json"
curl -fsSI "https://yourdomain.com/.well-known/oauth-protected-resource" | grep -iE "content-type|access-control"

Key Empirical & Architectural Takeaways

  • Using location ^~ /.well-known/ stops Nginx from evaluating regex locations (or falling back to a root location / { try_files $uri /index.html; } SPA rule) and guarantees missing manifests return true HTTP 404.
  • Setting default_type application/json; charset utf-8; solves Nginx's default application/octet-stream fallback on extensionless RFC 9728/8414 paths.
  • Remember Nginx's classic add_header inheritance trap: adding ANY add_header inside location ^~ /.well-known/ drops server-level HSTS/XCTO headers unless re-included inside that location block.

Common Production Pitfalls to Avoid

  • Forgetting the ^~ modifier lets regex blocks like location ~* \.json$ override CORS or caching unexpectedly.
  • Using try_files $uri $uri/ /index.html inside /.well-known/ causes nonexistent manifests to return 200 HTML instead of 404.
  • Omitting always on add_header drops CORS headers when returning 4xx responses.

More Agent Discovery Specifications & Framework Guides

← Back to AI Agent Discovery Generator & Validator Hub

Frequently Asked Questions

Why does Nginx wipe out my HSTS header on /.well-known/agent-card.json?

By design, Nginx does not inherit add_header directives from server {} into any location {} block that declares its own add_header. Re-include your server security headers snippet inside location ^~ /.well-known/.

Why use try_files $uri =404 inside /.well-known/ on a single-page app server?

Without =404, requests for unimplemented discovery endpoints fall back to index.html with HTTP 200 OK, tricking A2A and MCP scanners into trying to JSON-parse HTML.

Does ACME / Let's Encrypt /.well-known/acme-challenge/ still work?

Place a more specific location ^~ /.well-known/acme-challenge/ block before or proxy it separately so Certbot HTTP-01 challenges keep plain text handling.