kiwix / kiwix-tools

Command line Kiwix tools: kiwix-serve, kiwix-manage, ...
https://download.kiwix.org/release/kiwix-tools/
GNU General Public License v3.0
433 stars 85 forks source link

Kiwix-serve: add option for a sub-path #518

Closed ThinkingGuy closed 2 years ago

ThinkingGuy commented 2 years ago

kiwix-server serves each ZIM through its own subdirectory, under the server root:

http://localhost:8080/wikipedia_en_all_maxi_2021-02 http://localhost:8080/wikipedia_ja_all_maxi http://localhost:8080/wikipedia_es_all_maxi_2021-02

Could an option be added to make all these appear under a common (user-configurable) subfolder? For example:

http://localhost:8080/kiwix/wikipedia_en_all_maxi_2021-02 http://localhost:8080/kiwix/wikipedia_ja_all_maxi http://localhost:8080/kiwix/wikipedia_es_all_maxi_2021-02

This would make it easier to publish kiwix through a reverse proxy, alongside other apps, all on the same host:

http://www.example.com/kiwix http://www.example.com/ampache http://www.example.com/mediagoblin

kelson42 commented 2 years ago

@ThinkingGuy AFAIK, just rename your ZIM files like you want and you will get the result you expect. I think you can do that as well in 3 lines of configuration at the reverse-proxy level.

kelson42 commented 2 years ago

Closing for now. If anythin addional is needed please reopen.

mgautierfr commented 2 years ago

This option already exists. It is the option --urlRootLocation (or -r) In you case -r kiwix.

ristein commented 2 years ago

This option already exists. It is the option --urlRootLocation (or -r) In you case -r kiwix.

is there also a way to enable this in the docker app? I got exactly the same problem but didn't look into the non-docker version as I thought I had to keep the terminal open for this. I also tried apache mod_substitute with no luck...

calebjones commented 3 months ago

For docker, with a minor patch to the start.sh file in /usr/local/bin, one could pass in a docker compose environment variable to control this:

#!/bin/sh

# Download if necessary a file
if [ ! -z "$DOWNLOAD" ]
then
    ZIM=`basename $DOWNLOAD`
    wget $DOWNLOAD -O "$ZIM"

    # Set arguments
    if [ "$#" -eq "0" ]
    then
        set -- "$@" $ZIM
    fi
fi

if [ -z "$PORT" ]
then
    PORT=8080
fi

if [ -z "$ROOTPATH" ]
then
    CMD="/usr/local/bin/kiwix-serve --port=$PORT $@"
else
    CMD="/usr/local/bin/kiwix-serve --urlRootLocation $ROOTPATH --port=$PORT $@"
fi

echo $CMD
$CMD

# If error, print the content of /data
if [ $? -ne 0 ]
then
    echo "Here is the content of /data:"
    find /data -type f
fi

Then in docker compose, something like this:


version: '3.3'
---
services:
  kiwix-serve:
    container_name: kiwix-serve
    ports:
      - 8080:8080
    image: ghcr.io/kiwix/kiwix-serve:latest
    volumes:
      - /host/path/to/data:/data
    command:
      - '*.zim'
    environment:
      ROOTPATH: /kiwix
    restart: unless-stopped