There are hundreds of sites that proxy their nginx. In each server section, a file is connected, so that you can quickly register configs for everyone at once.
Until now, I registered various conditions, everything was fine until I came across location and proxy_pass.
The fact is that proxy_pass requires to register a backend. In my case, hundreds of sites have different backends in the form of IP addresses. These IPs, for example, coincide with the listens in the server section. If the value of proxy_pass does not match the listen, then it returns 404 for the specified location.
How can I automatically determine the backend corresponding to the site? Maybe somehow you can pull the IP value out of listen?
Here is the code that includes each site:
location ~ ^/(wp-admin|wp-login\.php|admin|administrator) { limit_req zone=wp burst=4 nodelay; proxy_pass http://IP:81; proxy_redirect http://IP/ /; proxy_set_header Host $host; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; }