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

implement / document way to set canonical URL for klaus site #140

Closed
jelmer opened this issue Oct 31, 2015 · 11 comments
Closed

implement / document way to set canonical URL for klaus site #140

jelmer opened this issue Oct 31, 2015 · 11 comments

Comments

@jelmer
Copy link
Contributor

jelmer commented Oct 31, 2015

I'm running klaus on a separate server, to which I proxy connections. This causes klaus to include the URL with the proxied server in any URLs, but that URL is not reachable for external users.

See e.g. https://jelmer.uk/klaus/etcd/

It would be great if there was a way to set the canonical URL to use in links, or if there is already a way to do this (through the frameworks used) if this could be documented.

@jonashaag
Copy link
Owner

Isn't this what the X-Forwarded-For header is for?

EDIT: X-Forwarded-Host.

@jelmer
Copy link
Contributor Author

jelmer commented Nov 2, 2015

On Sun, Nov 01, 2015 at 01:42:44PM -0800, Jonas Haag wrote:

Isn't this what the *X-Forwarded-For` header is for?
No, that just indicates the IP of the upstream proxy (see
http://https://en.wikipedia.org/wiki/X-Forwarded-For). This needs to override
the base URL for the klaus app.

Jelmer

@jonashaag
Copy link
Owner

I think you missed my edit, probably due to reading the message as an email

@jelmer
Copy link
Contributor Author

jelmer commented Nov 2, 2015

On Mon, Nov 02, 2015 at 04:35:07AM -0800, Jonas Haag wrote:

I think you missed my edit, probably due to reading the message as an email
Ah, indeed. Bad GitHub. :-(

X-Forwarded-Host is better, but still doesn't include the full URL, including e.g. the subpath.

@jonashaag
Copy link
Owner

Hm. There should be some canonical way to do this with the support of the Web framework (Flask here, but this should be available in any Web framework). I don't know how exactly the solution looks like, but I'd be surprised if this wasn't a common use case that has been solved in a general way.

@jelmer
Copy link
Contributor Author

jelmer commented Nov 2, 2015

On Mon, Nov 02, 2015 at 06:21:18AM -0800, Jonas Haag wrote:

Hm. There should be some canonical way to do this with the support of the Web
framework (Flask here, but this should be available in any Web framework). I
don't know how exactly the solution looks like, but I'd be surprised if this
wasn't a common use case that has been solved in a general way.
Yeah, I was thinking the same thing (but couldn't easily find it). Hence the
request to have it documented if not implemented. :)

jelmer

@jonashaag
Copy link
Owner

Ok, just had a look at the source (utils.py:SubUri). This should already be possible by setting the X-Forwarded-Host, X-Script-Name and X-Scheme headers in the reverse proxy. If it works, feel free to add a short entry to the wiki.

@jelmer
Copy link
Contributor Author

jelmer commented Nov 2, 2015

On Mon, Nov 02, 2015 at 08:00:12AM -0800, Jonas Haag wrote:

Ok, just had a look at the source (utils.py:SubUri). This should already be possible by setting the X-Forwarded-Host, X-Script-Name and X-Scheme headers in the reverse proxy. If it works, feel free to add a short entry to the wiki.
Setting X-Script-Name seems to have an effect, but the others don't. I'll see if I can find out more tonight.

@jelmer
Copy link
Contributor Author

jelmer commented Nov 2, 2015

On Mon, Nov 02, 2015 at 08:00:12AM -0800, Jonas Haag wrote:

Ok, just had a look at the source (utils.py:SubUri). This should already be possible by setting the X-Forwarded-Host, X-Script-Name and X-Scheme headers in the reverse proxy. If it works, feel free to add a short entry to the wiki.
With your changes I can also use X-SCHEME correctly. However, there is still no good way to specify the host as far as I can tell.

The alternative that does seem to be is to use werkzeug.contrib.fixers.ProxyFix, and wrap klaus in that:

from werkzeug.contrib.fixers import ProxyFix
application = ProxyFix(application.wgsi_app)

@jonashaag
Copy link
Owner

The alternative that does seem to be is to use werkzeug.contrib.fixers.ProxyFix, and wrap klaus in that:

from werkzeug.contrib.fixers import ProxyFix
application = ProxyFix(application.wgsi_app)

This seems to be the correct way to do it at the time of this writing. Do you think we should add support for adding ProxyFix in make_app or does it suffice to add some documentation about it?

@jonashaag
Copy link
Owner

Cool, thanks, I made a few modifications here and there and changed it so it's bit more independent from the actual proxy software used. I consider this case closed :-)

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

No branches or pull requests

2 participants