Fixing CORS errors (and PUBLIC_URL)
If your browser shows errors like:
- “Blocked by CORS policy”
- “has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header”
- The UI shows a Public URL mismatch warning
…your instance is usually being accessed from a different origin than the server is configured to allow.
The quick fix (most common)
- Decide the one URL you will use to access nextExplorer (scheme + host + optional port), for example:
https://files.example.com
- Set it on the server:
PUBLIC_URL=https://files.example.com
- Restart the container/app.
If you access nextExplorer from multiple domains (or you have a separate frontend domain), also set CORS_ORIGINS.
CORS environment variables
CORS_ORIGINS / CORS_ORIGIN / ALLOWED_ORIGINS
- What it is: A comma-separated list of allowed origins (no paths).
- Examples:
CORS_ORIGINS=https://files.example.comCORS_ORIGINS=https://files.example.com,https://admin.example.comCORS_ORIGINS=http://localhost:5173(local dev frontend)
Notes:
- Origins must match exactly (scheme + host + port).
https://files.example.comis different fromhttp://files.example.comandhttps://files.example.com:8443. - Use
CORS_ORIGINSwhen the app is accessed from multiple origins (for example, multiple reverse-proxy hostnames).
PUBLIC_URL (what it does, and what depends on it)
PUBLIC_URL is nextExplorer’s external base URL (no trailing slash). It should match the URL users type into the browser.
When set correctly, it drives several behaviors:
- CORS defaults: If you don’t set
CORS_ORIGINS, nextExplorer defaults CORS to the origin ofPUBLIC_URL. - UI safety checks: The frontend compares the current browser origin to the server’s expected public origin and shows a mismatch warning when they differ.
- Reverse proxy + cookies: When
PUBLIC_URLis set, nextExplorer enables a safe defaultTRUST_PROXYso Express can correctly interpretX-Forwarded-*headers (important for HTTPS and cookie security behind a proxy). - OIDC callbacks: If you don’t set
OIDC_CALLBACK_URL, it defaults to${PUBLIC_URL}/callback. - Sharing links: Share URLs are built from
PUBLIC_URLwhen available (otherwise they fall back to the incoming request host). - ONLYOFFICE / Collabora: These integrations need a correct
PUBLIC_URLto build absolute URLs that the document server calls back.
Common configurations
Single domain (recommended)
If the UI and API are served from the same origin (typical reverse proxy setup), just set:
bash
PUBLIC_URL=https://files.example.comYou usually do not need CORS_ORIGINS in this case.
Multiple domains
If users access the same instance from multiple origins, add them all:
bash
PUBLIC_URL=https://files.example.com
CORS_ORIGINS=https://files.example.com,https://files-alt.example.comLocal dev frontend
If you run the backend at http://localhost:3000 and the frontend dev server at http://localhost:5173:
bash
PUBLIC_URL=http://localhost:3000
CORS_ORIGINS=http://localhost:5173If it still fails
- Confirm your reverse proxy forwards
X-Forwarded-Proto,X-Forwarded-Host, andX-Forwarded-For. - Make sure you’re visiting the exact
PUBLIC_URL(includinghttpsvshttpand ports). - Double-check there’s no browser cache/service-worker holding onto an old origin.
