I would like any incoming HTTP request (regardless of domain name) that begin with a certain path to be sent to a local server. For example:
location /special/path/ {
proxy_pass http://127.0.0.1:8000/;
}
If there is no matching server {}
block for a given domain name, Nginx will route the request to the default_server
. But I need the request to always be routed to the local server, even if a matching server {}
block is found.
How would I go about this?
Bonus: if there is a way to do this outside of the server {}
that currently has default_server
set, that would be awesome.
I think you might have to configure a suitable block in every server. You can do this with an include rather than copy and paste. This should work in the default server.
So in each server block use something like this
And in /etc/nginx/fragments/path.conf
Note that you shouldn't put it in the sites-enabled directory as the nginx.conf includes them, and it's invalid syntax in that context.
Someone else may have a better way than this, but I believe this will work.