Problem

When using NGINX to proxy pass my FRP dashboard site, FRP hardcodes absolute path /static to the web logic. Thus, when NGINX tries to proxy pass path /frp to 127.0.0.1:<dashboard port>, FRP will send static file requests to /static, which cannot be captured by /frp location, leading to a 404.


Solution

Concept

Capture /static/ location in NGINX and rewrite URI to be preceded by /frp.

This solution is generalizable and can be used to proxy any absolute paths.

Code

location /static/ {
	rewrite ^ $scheme://$host/frp$uri;
}

Additional Notes

Limitation

With this rewrite scheme, there can only be one application using /static/, and the actual /static/ path should not exist, as they get overwritten by this NGINX location. This should be a fundamental limitation, as NGINX has no information of which application is calling /static/ when absolute paths are used (this might be doable with request fields?).


References

FRP GitHub issue