I have a location
block as
location @test{ proxy_pass http://localhost:5000/1; }
but nginx complains that "proxy_pass cannot have URI part in location given by regular expression..."
Does anyone know what might be wrong?
I'm trying to query localhost:5000/1 when an upload is complete:
location /upload_attachment { upload_pass @test; upload_store /tmp; ... }
nginx cannot process your desired URI part in the proxy_pass directive because you're within a named location (hence the error message). This is because nginx is built in a modular fashion and each configuration block is read in various stages by the various modules.
2018/11/17 16:47:03 [emerg] 1#1: "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/nginx.conf:36 I've gone through several examples and reviewed a number of answers and I believe that the configuration I have should work.
A simple example A proxy_pass is usually used when there is an nginx instance that handles many things, and delegates some of those requests to other servers. Some examples are ingress in a Kubernetes cluster that spreads requests among the different microservices that are responsible for the specific locations.
You can circumvent nginx's requirement for all hosts to be available at startup by using variables inside the proxy_pass directives. HOWEVER, for some unfathomable reason, if you do so, you require a dedicated resolver directive to resolve these paths. For Kubernetes, you can use kube-dns. kube-system here.
Technically just adding the URI should work, because it's documented here and it says that it should work, so
location @test{ proxy_pass http://localhost:5000/1/; # with a trailing slash }
Should have worked fine, but since you said it didn't I suggested the other way around, the trick is that instead of passing /my/uri
to localhost:5000/1
, we pass /1/my/uri
to localhost:5000
,
That's what my rewrite did
rewrite ^ /1$1
Meaning rewrite the whole URL, prepend it with /1
then add the remaining, the whole block becomes
location @test{ rewrite ^ /1$1; proxy_pass http://localhost:5000; }
Note: @Fleshgrinder provided an answer explaining why the first method didn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With