Incorrect URLs when served behind a proxy with base_url set
See original GitHub issueI’m running datasette serve --config base_url:/foo/ …
, proxying to it with this Apache config:
ProxyPass /foo/ http://localhost:8001/
ProxyPassReverse /foo/ http://localhost:8001/
and then accessing it via https://example.com/foo/
.
Although many of the URLs in the pages are correct (presumably because they either use absolute paths which include base_url
or relative paths), the faceting and pagination links still use fully-qualified URLs pointing at http://localhost:8001
.
I looked into this a little in the source code, and it seems to be an issue anywhere request.url
or request.path
is used, as these contain the values for the request between the frontend (Apache) and backend (Datasette) server. Those properties are primarily used via the path_with_…
family of utility functions and the Datasette.absolute_url
method.
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
base url support · Issue #241 · coder/code-server - GitHub
I wanne run behind proxy. ... Each server serves with baseurl like “/code-server/:server_id/“ . ... This is a wrong server url.
Read more >How to handle relative urls correctly with a nginx reverse proxy
The problem is basically that using a proxy_pass directive won't rewrite HTML code and therefor relative URL's to for instance a img ...
Read more >GeoServer accidentally sat up a proxy base URL from Admin ...
Found that the setting in web.xml overrides the setting put in the Admin gui. So I just got it sorted by putting the...
Read more >Django behind a proxy: Fixing absolute URLs - Ubuntu
It turns out this is the problem. Because Apache, and not the user directly, is making the request to Django, Django sees the...
Read more >Confluence BaseURL from Jumphost - Atlassian Community
You say "base url is not available from the proxyserver" - that means your proxy is incorrect, it is supposed to be serving...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let’s reopen this.
I think this could be solved by one of:
base_url
into account (as they do now, yay!).base_url
to include the expected frontend origin, and then use that information when generating absolute URLs.X-Forwarded-*
family of conventional headers) to pass the frontend origin information to Datasette, and then use that information when generating absolute URLs.Option 1 seems like the easiest to me, if you can get away with never having to generate an absolute URL.