The error "Unexpected token ‘U’, ... is not valid JSON" when deploying Phoenix behind nginx with a path prefix is typically caused by a misconfiguration of the root path or reverse proxy, resulting in static assets or API endpoints being requested from the wrong location. The environment variable `PHOENIX_HOST_ROOT_PATH` must be set (as you did), but it only works correctly if the reverse proxy is configured to forward requests with the prefix and rewrite paths accordingly. The sub_filter directives alone are not sufficient; you must ensure nginx forwards the correct path and does not strip or double the prefix, and that all static assets and API calls are routed through `/phoenix_root_path` as expected by Phoenix. This is a common issue and is documented in the <https://github.com/Arize-ai/phoenix/blob/main/examples/reverse-proxy/README.md|reverse proxy example> and <https://docs.arize.com/phoenix/self-hosting/configuration|configuration docs>.
Additionally, the error can occur if the proxy is not rewriting paths correctly, causing the Phoenix server to return an HTML error page (e.g., 404 or 400) instead of JSON, which the frontend then tries to parse as JSON. Double-check your nginx config to ensure the `location` block matches the prefix, and that `proxy_pass` does not add or remove slashes incorrectly. See <https://github.com/Arize-ai/phoenix/issues/5254|this issue> and <https://arize-ai.slack.com/archives/C04R3GXC8HK/p1723547289.869949|Slack discussion> for similar troubleshooting. Would you like a step-by-step nginx config example for Phoenix behind a path prefix?
Sources:
- <https://github.com/Arize-ai/phoenix/blob/main/examples/reverse-proxy/README.md|Phoenix reverse proxy example>
- <https://github.com/Arize-ai/phoenix/issues/5254|GitHub Issue: static files fail to load with ingress prefix>
- <https://docs.arize.com/phoenix/self-hosting/configuration|configuration docs>
- <https://arize-ai.slack.com/archives/C04R3GXC8HK/p1723547289.869949|Slack discussion>