koel / docker

A minimal docker image for the koel music streaming server.
https://hub.docker.com/r/phanan/koel/
MIT License
178 stars 54 forks source link

Provide working nginx reverse proxy config example #93

Open jantonz opened 3 years ago

jantonz commented 3 years ago

FYI: I think it's related to your card https://github.com/koel/docker/projects/1#card-31191171

Using a reverse proxy is a common way of accessing dockerized services outside your local network. Some typical reverse proxy docker images include Traefik and SWAG. The latter, SWAG, is extremely easy to use and I do have a working configuration for Koel (in the case of using Linuxserver's latest SWAG docker container, this config should be placed by default in ~/.config/appdata/swag/nginx/proxy-confs/koel.subdomain.conf):

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name koel.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {

        include /config/nginx/proxy.conf;
        resolver 127.0.0.11 valid=30s;
        set $upstream_app koel;
        set $upstream_port 8090;
        set $upstream_proto http;
        proxy_pass $upstream_proto://<your_server_ip>:$upstream_port;
    }

    location ~ (/koel)?/api {
        include /config/nginx/proxy.conf;
        resolver 127.0.0.11 valid=30s;
        set $upstream_app koel;
        set $upstream_port 8090;
        set $upstream_proto http;
        proxy_pass $upstream_proto://<your_server_ip>:$upstream_port;

   }
}

For this config to work, however, the environment variable FORCE_HTTPS=true needs to be added in the compose file for koel; otherwise, a blank page is served (no error, only a blank, uninformative page). For completion, this is an extract of the docker-compose.yml used for these services: SWAG and Koel:

version: "3.7"

services:
  koel:
    image: hyzual/koel
    container_name: koel
    depends_on:
      - database
    ports:
      - 8090:80
    networks:
      - proxy  
    environment:
      - FORCE_HTTPS=true
      - DB_CONNECTION=pgsql
      - DB_HOST=database
      - DB_USERNAME=koel
      - DB_PASSWORD=<koel_password>
      - DB_DATABASE=koel
    volumes:
      - music:/music
      - covers:/var/www/html/public/img/covers
      - search_index:/var/www/html/storage/search-indexes

  database:
    image: postgres:13
    container_name: koel-db
    volumes:
      - db:/var/lib/postgresql/data'
    environment:
      - POSTGRES_DB=koel
      - POSTGRES_USER=koel
      - POSTGRES_PASSWORD=koel_password_0987

  swag:
    image: ghcr.io/linuxserver/swag
    hostname: ${DOCKERHOSTNAME}
    ports:
      - ${SWAG_PORT_443}:443
      - ${SWAG_PORT_80}:80
    cap_add:
      - NET_ADMIN
    networks:
      - proxy
    container_name: swag
    environment:
      - DNSPLUGIN=${SWAG_DNSPLUGIN}
      - DUCKDNSTOKEN=${SWAG_DUCKDNSTOKEN}
      - EMAIL=${SWAG_EMAIL}
      - EXTRA_DOMAINS=${SWAG_EXTRA_DOMAINS}
      - ONLY_SUBDOMAINS=${SWAG_ONLY_SUBDOMAINS}
      - PGID=${PGID}
      - PUID=${PUID}
      - SUBDOMAINS=${SWAG_SUBDOMAINS}
      - TZ=${TZ}
      - URL=${SWAG_URL}
      - VALIDATION=${SWAG_VALIDATION}
      - MAXMINDDB_LICENSE_KEY=${SWAG_MAXMINDDB_LICENSE_KEY}
    logging:
      driver: json-file
      options:
        max-file: ${DOCKERLOGGING_MAXFILE}
        max-size: ${DOCKERLOGGING_MAXSIZE}
    restart: ${SWAG_RESTART}
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DOCKERCONFDIR}/swag:/config
      - ${DOCKERSTORAGEDIR}:/storage

networks:
  proxy:
    external: true