Support X-Forwarded-Prefix header for reverse proxied deployments on non-standard paths (not /erddap)#357
Conversation
|
Docker compose stack demonstrating reverse proxies using Apache httpd and nginx with and without the compose.yaml: httpd-virtual-host.conf: nginx-server.conf: |
b7e5c02 to
c07c59f
Compare
…non-standard paths (not /erddap)
Add support for the non-standard X-Forwarded-Prefix request header
for use by reverse proxies (Apache httpd, nginx, etc) when ERDDAP
is hosted on a non-standard path (i.e. other than /erddap).
Reverse proxies should add a X-Forwarded-Prefix request header specifying
the non-standard path prefix if ERDDAP is not served at /erddap.
Apache http example:
<VirtualHost *:81>
ProxyPreserveHost On
RequestHeader set X-Forwarded-Prefix /subpath
ProxyPass /subpath/erddap http://localhost:8080/erddap
</VirtualHost>
nginx example:
server {
listen 80;
location /subpath/erddap {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Prefix /subpath;
proxy_pass http://localhost:8080/erddap;
}
}
c07c59f to
9d77db3
Compare
| && request.getHeader("Host") != null | ||
| && ("https".equals(request.getScheme()) || !request.getHeader("Host").contains(":"))) { | ||
| httpsUrl = "https://" + request.getHeader("Host") + "/" + config.warName; | ||
| httpsUrl = "https://" + getHostAndPathFromRequest(request) + "/" + config.warName; |
There was a problem hiding this comment.
Is this going to end up with /erddap/erddap/ in the url? The config.warName defaults to "erddap". Or is 'erddap' not in the prefix?
There was a problem hiding this comment.
In the current implementation /erddap is not supposed to be in the prefix, i.e. X-Forwarded-Prefix would be set to /subpath for an ERDDAP at /subpath/erddap. In other words, X-Forwarded-Prefix should only be set for non-standard deployment paths, and it should be set to the path prefix before /erddap. We could change it to be the full path to the ERDDAP deployment, but then config.warName would be ignored which seems confusing.
There was a problem hiding this comment.
That makes sense. The current approach is good.
I'm still reading through the associated documentation updates. Once I finish there, if I have no other questions I'll approve this.
|
@srstsavage @ChrisJohnNOAA If you want a reason why this construct might be used, many people like our group are severely hampered in creating new hostnames, even if going to the same computer. It takes months of delays, a hearing by a panel, and then usually is declined. But if I want to create a second ERDDAP on the same machine I can do https://my_exisitng_host/new_erddap/erddap without approval. Also in looking that the list of servers in erddap.com there are a number of sites using the same construct, I don't know there rationale just that it exists. |
|
Yep, I think services in general should be able to be deployed at arbitrary paths to support deployment scenarios like you describe. I didn't think it was possible due to assumptions in the ERDDAP code based on past comments, but seems to generally be working. There may be assumptions in the ERDDAP federation logic, but it might also just be looking for |
|
@ChrisJohnNOAA @srstsavage Okay I just tested this at https://oceanwatch.pfeg.noaa.gov/noaa_wide/erddap. and it appears to be working okay. This is 2.28.1 with using headers sent to true. Thanks |
Description
Add support for the non-standard X-Forwarded-Prefix request header for use by reverse proxies (Apache httpd, nginx, etc) when ERDDAP is hosted on a non-standard path (i.e. other than
/erddap).Reverse proxies should add a
X-Forwarded-Prefixrequest header specifying the non-standard path prefix if ERDDAP is not served at/erddap.Apache http example:
nginx example:
Type of change
Please delete options that are not relevant.
Checklist before requesting a review