question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect URLs when served behind a proxy with base_url set

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
simonwcommented, Mar 10, 2021

Let’s reopen this.

0reactions
tsibleycommented, Mar 10, 2021

I think this could be solved by one of:

  1. Stop generating absolute URLs, e.g. ones that include an origin. Relative URLs with absolute paths are fine, as long as they take base_url into account (as they do now, yay!).
  2. Extend base_url to include the expected frontend origin, and then use that information when generating absolute URLs.
  3. Document which HTTP headers the reverse proxy should set (e.g. the 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found