Fix nginx invalid URL prefix in proxy_pass
Fix nginx invalid URL prefix by checking the proxy_pass scheme, choosing HTTP or HTTPS to match the backend, and retesting the configuration.
2026/11/21 23:19:44 [emerg] 1#1: invalid URL prefix in /lab/before.conf:6nginx: [emerg] invalid URL prefix in /lab/before.conf:6nginx: configuration file /lab/before.conf test failedWhen nginx -t reports invalid URL prefix, check how the proxy_pass URL begins on the reported line. For a fixed URL, use http:// for an HTTP backend or https:// for a backend that accepts HTTPS.
[1] Open the file and line from the error. The container ran nginx -t -c /lab/before.conf. In the test above, nginx stopped at ftp:// on line 6. If your deployment generates the configuration, find the line in the file nginx actually reads and check the template or input that supplies the value.
events {}http { server { listen 127.0.0.1:18080; location / { proxy_pass ftp://127.0.0.1:18081; } }}For a literal URL, nginx 1.28.0 checks for http:// or https:// before processing the address. A missing slash, as in http:/, or a bare address also fails this check. Check the scheme before editing the hostname or port. The prefix in this message is the start of the URL. Leave the location / path as it is.
[2] Check which protocol the backend accepts and update the proxy_pass scheme. Save a known-good configuration outside the paths matched by include. In this test, the change from ftp:// to http:// leaves the address, port, and location intact.
events {}http { server { listen 127.0.0.1:18080; location / { proxy_pass http://127.0.0.1:18081; } }}[3] Test the edited configuration. The container loads the edited file from /lab/after.conf. On the running deployment, use nginx -t with the same configuration file the service uses. If the service specifies a nondefault configuration, pass that filename with -c.
$ nginx -t -c /lab/after.confnginx: the configuration file /lab/after.conf syntax is oknginx: configuration file /lab/after.conf test is successfulThe check went from exit code 1 to 0. The test used no running backend and sent no requests. In production, reload using the usual deployment procedure after the check passes, then request the route and inspect the response and error log. If the change causes a 502 and the destination is wrong, restore the known-good configuration, test it, and reload. For connection refusals or TLS handshake errors, see nginx 502 Bad Gateway logs.
[4] If invalid URL prefix in "…" appears only when a request arrives, check the values of any variables used in proxy_pass. nginx 1.28.0 evaluates a variable URL at request time and checks its prefix separately. If a map builds the URL, check the value selected by the failing request and the default value. Keep sensitive query values out of any shared log excerpts.
For cannot have URI part, see proxy_pass URI restrictions in regex locations. For invalid number of arguments, see checking proxy_pass arguments and semicolons.
Analyze your Nginx log in the browser ↗ — nothing is uploaded.