Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom base URL to play nice with reverse proxy #127

Closed
wallace11 opened this issue May 18, 2021 · 6 comments · Fixed by #313
Closed

Add support for custom base URL to play nice with reverse proxy #127

wallace11 opened this issue May 18, 2021 · 6 comments · Fixed by #313

Comments

@wallace11
Copy link

I've been trying to set a reverse proxy for linkding for hours.
I'm using SWAG which includes a Let's Encrypt integration and an NGINX server with a relatively easy to configure templates.

This setting should've been enough:

location /bm/ {
	include /config/nginx/proxy.conf;
	resolver 127.0.0.11 valid=30s;
	set $upstream_app linkding;
	set $upstream_port 9090;
	set $upstream_proto http;
	proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}

Note: linkding is the container name, and I've been trying to set www.mysite.com/bm as the access URL.

No matter what I'm doing, the internal linkding server is getting /bm/ which it doesn't know how to process:

[pid: 12|app: 0|req: 1/1] 172.22.0.4 () {48 vars in 947 bytes} [Tue May 18 10:46:08 2021] GET /bm/ => generated 77 bytes in 255 msecs (HTTP/1.1 404) 5 headers in 153 bytes (1 switches on core 0)

Maybe there's a way to circumvent that, but I see that most self hosted apps allow for setting a base URL (which in my case would be /bm/) to tell the app where the start point is.

@sissbruecker
Copy link
Owner

While that would be a nice to have feature, it seems you could work around your issue if you would use a sub-domain instead of a folder: bm.mysite.com

Another option are URL rewrites I think, but I don't have experience with that.

hollispotter pushed a commit to hollispotter/linkding that referenced this issue May 22, 2021
Add support for running LinkDing under a custom path to match reverse proxy configurations.
Locally tested with nginx+certbot+docker-compose, supports two new optional env variables:
LD_CONTEXT_PATH=/linkding
LD_CONTEXT_STATIC_PATH=/linkding/static
@hollispotter
Copy link

hollispotter commented May 23, 2021

Hi, I ran into the same issue. I've forked the repo and fixed it for my own use. You can see the changes here:

hollispotter@6ac7d46

It introduces two environment variables:

  • LD_CONTEXT_PATH
  • LD_CONTEXT_STATIC_PATH

This lets me set them to "/linkding" and "/linkding/static" in my docker-compose.yml, and have it all work merrily with the other dozen services I run. Neither workaround mentioned was practical for me, but thank you for all your effort in developing this.

If you would like, I can send this as a pull request. It's a fairly minor change, but I am not a Python/Django developer by trade and consider this a bit of a hack.

@sissbruecker
Copy link
Owner

sissbruecker commented May 24, 2021

@hollispotter Looks like a good start, but it would need some improvements:

  • instead of duplicating the env variable everywhere introduce a setting that is then reused
  • the change to the url patterns assumes that a base url will be present and prepends a / to the paths even if there is no base url
  • this needs some way of testing to verify that the app works with/without base URL, easiest is probably to run the test suite with the env variable set, and having a test case that generates a few URLs to check if the setting is respected
  • the option would need to be documented in options.md so that it's discoverable

If you want to work on those points, feel free to open a PR.

@qiaohao9
Copy link
Contributor

Is there any follow-up here?

@ghost
Copy link

ghost commented Jan 5, 2022

I'm also interested in a base URL option and am confirming that I haven't been able to find any combination of rewrite rules for Nginx that accommodates it in linkding's current implementation.

@gingerbeardman
Copy link
Contributor

gingerbeardman commented Feb 22, 2022

I'm using it on Synology with a subdomain and reverse proxy — all is well.

Screenshot 2022-02-22 at 12 58 57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants