Working with nginx and installing on URL prefixes
Hello, I’m trying to make an install of koha to consider migrating to it from another ILS. Given our existing infrastructure the setup scheme of koha on different domains is not entirely convenient for us nor is using apache (even if only proxied by nginx we rather not add more moving part to our infrastructure). Ideally we would like to be able to have: 1. The opac on say example.org/koha/catalogue 2. The staff interface on say example.org/koha/intranet 3. Use the official debian packages 4. Use nginx directly instead of apache I haven’t been succeeding so far. But I’m at a point where I can `koha-plack —start mylib` and convince nginx to talk to plack on the prefixes by having: location /koha/intranet { include proxy_params; proxy_pass unix:/var/run/koha/mylib/plack.sock:/intranet/mainpage.pl; proxy_buffer_size 8k; } location /koha/catalogue { include proxy_params; proxy_pass unix:/var/run/koha/mylib/plack.sock:/opac; proxy_buffer_size 8k; } I gather there’s an additional bunch of rewrites rules in the the apache configuration files that I will have to port at some point but one thing I’m stuck on is that when I try to access `example.org/koha/intranet` it redirects to the root of the domain `example.org/cgi-bin…` rather than `example.org/koha/intranet/cgi-bin…` to trigger the install procedure. So here are two questions: a) Is there an easy way to convince koha to root its URLs w.r.t. to the prefix we’d like them to be on ? Maybe an environment variable or a launch parameter or an http header to set in the nginx configuration ? (I’m a bit unfamiliar with the whole plack/starman eco-system) b) Is there any strong problem I’m not seeing in trying to setup koha the way I outlined above and use nginx rather than apache to serve the app ? Thanks, Daniel P.S. I also vaguely considered the `app.psgi` part of the source distribution but this workflow doesn’t seem to be documented or supported in the debian packages from which I rather not deviate too much.
Hi! On Fri, Oct 06, 2023 at 01:04:20PM +0200, Daniel Bünzli wrote:
a) Is there an easy way to convince koha to root its URLs w.r.t. to the prefix we’d like them to be on ? Maybe an environment variable or a launch parameter or an http header to set in the nginx configuration ? (I’m a bit unfamiliar with the whole plack/starman eco-system)
AFAIK there isn't, and I had the same problem some time ago. The problem is mainly that a LOT of templates have hardcoded URLs starting with "/" in them (instead of using a resolver like uri_for, which could then consider some HTTP Headers to fiddle with the paths) We ended up with some rather ugly rewrites (of the content, not the URLs!!!) using mod_substitute and mod_filter, plus a bunch of mod_rewrites (which are comparably easy) <Location "/some-other-path/"> AddOutputFilterByType SUBSTITUTE text/html text/plain application/json application/javascript Substitute "s|/cgi-bin/|/some-other-path/cgi-bin/|i" Substitute "s|/intranet-tmpl/|/some-other-path/intranet-tmpl/|i" Substitute "s|/api/v1/|/some-other-path/api/v1/|i" </Location> This will take the output generated upstream (i.e. plack) and do actual regex replaces on the HTML. So ... ugh...
b) Is there any strong problem I’m not seeing in trying to setup koha the way I outlined above and use nginx rather than apache to serve the app ?
There might be some long-running scripts left that can only be run as CGI (because they fork). You can find those in apache-shared-intranet-plack.conf after "# FIXME: These scripts should be fixed so they..." (at least in 22.11). But maybe they all have been ported to RabbitMQ, in which case I think there should be no problems using nginx as a frontend (or maybe they can also be made to work with nginx?) But maybe I also remeber this wrong, but I think we decided to keep Apache (even though I'd rather use nginx) because of these issues... Hope that helps, Greetings, domm -- Thomas Klausner domm https://domm.plix.at Just another ( Perl | Postgres | Bicycle | Food | Photo | Vinyl ) Hacker A not-so-short list of things I learned at PerlKohaCon #Perl #Koha [ 2023-08-19 10:00 > https://domm.plix.at/perl/2023_08_things_i_learned_at_perlkohacon.html ] Long and good read: http://bit-player.org/2023/ai-and-the-end-of-programming [ 2023-09-14 12:01 > https://domm.plix.at/microblog.html ]
Thanks for your answer Thomas.
This will take the output generated upstream (i.e. plack) and do actual regex replaces on the HTML. So ... ugh…
Ugh indeed :-) Do you think there would be consideration from the devs for this problem, that is the ability to serve koha on URL prefixes ? The current scheme makes it a bit inconvenient to integrate koha on existing infrastructures and I rather not get too much into the ugh workarounds, it’s annoying for everyone when we run into bugs. Should I perhaps open an issue about this ?
b) Is there any strong problem I’m not seeing in trying to setup koha the way I outlined above and use nginx rather than apache to serve the app ?
There might be some long-running scripts left that can only be run as CGI (because they fork).
If that’s the only problem one could still run these through fcgiwrap [1]. We are actually already running it for other purposes. Best, Daniel [1]: https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/
I think that is bug 15045 (no patch!) https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15045 Le ven. 6 oct. 2023 à 16:39, Daniel Bünzli <daniel.buenzli@erratique.ch> a écrit :
Thanks for your answer Thomas.
This will take the output generated upstream (i.e. plack) and do actual regex replaces on the HTML. So ... ugh…
Ugh indeed :-)
Do you think there would be consideration from the devs for this problem, that is the ability to serve koha on URL prefixes ?
The current scheme makes it a bit inconvenient to integrate koha on existing infrastructures and I rather not get too much into the ugh workarounds, it’s annoying for everyone when we run into bugs.
Should I perhaps open an issue about this ?
b) Is there any strong problem I’m not seeing in trying to setup koha the way I outlined above and use nginx rather than apache to serve the app ?
There might be some long-running scripts left that can only be run as CGI (because they fork).
If that’s the only problem one could still run these through fcgiwrap [1]. We are actually already running it for other purposes.
Best,
Daniel
[1]: https://www.nginx.com/resources/wiki/start/topics/examples/fcgiwrap/
_______________________________________________
Koha mailing list http://koha-community.org Koha@lists.katipo.co.nz Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
On Fri, Oct 06, 2023 at 04:39:15PM +0200, Daniel Bünzli wrote:
Do you think there would be consideration from the devs for this problem, that is the ability to serve koha on URL prefixes ?
The current scheme makes it a bit inconvenient to integrate koha on existing infrastructures and I rather not get too much into the ugh workarounds, it’s annoying for everyone when we run into bugs.
I agree!
Should I perhaps open an issue about this ?
That might be a good idea. Here are two threads from last year where I had similar problems: https://lists.koha-community.org/pipermail/koha-devel/2022-April/047011.html https://lists.koha-community.org/pipermail/koha-devel/2022-August/047266.htm... Here is a nice suggestion on how to get this into Koha: https://lists.koha-community.org/pipermail/koha-devel/2022-August/047271.htm... Which I was too lazy to do (esp as it's mostly QA work), and instead implemented the aforementiones rewrite hack. But if there were people working on it, I would definitly join! Greetings, domm -- Thomas Klausner domm https://domm.plix.at Just another ( Perl | Postgres | Bicycle | Food | Photo | Vinyl ) Hacker A not-so-short list of things I learned at PerlKohaCon #Perl #Koha [ 2023-08-19 10:00 > https://domm.plix.at/perl/2023_08_things_i_learned_at_perlkohacon.html ] Long and good read: http://bit-player.org/2023/ai-and-the-end-of-programminge 2023-09-14 12:01 > https://domm.plix.at/microblog.html ]
Thanks all for the references.
Here is a nice suggestion on how to get this into Koha: https://lists.koha-community.org/pipermail/koha-devel/2022-August/047271.htm...
Indeed. The gradual strategy mentioned there seems quite sensitive. Maybe a link to it should be provided in Jonathan’s reference here: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15045
But if there were people working on it, I would definitly join!
Not a perl programmer myself and entirely unfamiliar with the code base but if someone gets at least the low-level url building function in, I could certainly give a hand to upgrade, review and test the templates and code. Best, Daniel
participants (3)
-
Daniel Bünzli -
Jonathan Druart -
Thomas Klausner