Disable caching when using a reverse proxy
Generate a general.conf without media caching for reverse proxy consumption.
Information
The routing does not pass through the proxy when location handling for media caching is present in the general.conf, instead nginx attempts to route these requests via the default site.
The directory of the default site - in my case - is empty. It doesn't contain the css or js resources the web app at the proxy_pass offers.
It is not desired and not reasonable to cache a proxy location by default.
Details
Description
This is caused by the location handling in general.conf included in every reverse proxy domain.
# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
}
# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
}
Steps to reproduce
- Create a basic node application and serve at
localhost:3000. - Create a NGINX Config with a proxy pass from the subdomain
app.example.comtolocalhost:3000. - Open your browser devtools network tab
- Request
app.example.comin your browser - Media types handled in
general.confwill fail with 404.
Expected behavior
Resources are requested from the reverse proxy
Screenshots
- - [25/Feb/2024:19:51:08 +0000] "GET /_app/immutable/chunks/entry.aDhfE7Nt.js HTTP/2.0" 404 548 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
- - [25/Feb/2024:19:51:08 +0000] "GET /_app/immutable/chunks/index.CA4DBg1v.js HTTP/2.0" 404 548 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
Yes, this issue cost me several hours today. While trying to use the generated configuration file to reverse proxy a Gitea service on the host, I found that many resource files (like index.js) were not loading properly.
In a natural setup, which I believe, we would certainly want the forwarded service to independently decide which to return. However, due to the generated files including nginxconfig.io/general.conf, the forwarding is blocked, which makes the auto-generated reverse proxy configuration almost unusable 😕 (I hate to manually modify an auto-generated file).
A simple workaround would be to avoid inserting the content of general.conf into the reverse proxy configuration file. Upon further thought, one also agree that the logic in that file should actually be handled by the proxied service itself, not by Nginx.
I wasted 3 hours debugging it. I agree with everything that was written. this needs to be fixed.