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

Docker container with koel behind nginx reverse proxy in non-root #116

Open
INNKCake opened this issue Dec 12, 2021 · 8 comments
Open

Docker container with koel behind nginx reverse proxy in non-root #116

INNKCake opened this issue Dec 12, 2021 · 8 comments

Comments

@INNKCake
Copy link

Description

I freshly installed Koel using the recommended Docker image and configured it to work under the Nginx reverse proxy in subfolder /koel. The page loads, but the most of the content is missing, and the links to the content are broken (https://example.com/img/icon.png instead of https://example.com/koel/img/icon.png). I tried to provide .env to container with both APP_URL and FORCE_HTTPS, but no luck - page still blank. It feels that variables are not passed properly for some reason.
If I revert my current Nginx config to use / - everything works fine.

Nginx confix

server {
    listen 80;
    server_name example.com;
    return 301 https://$server_name$request_uri;
}

upstream koel {
    server 127.0.0.1:5050;
    keepalive 64;
}

server {
    server_name example.com www.example.com;
    index index.html index.htm index.php;
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    client_max_body_size 100M;
    client_body_timeout 30s;
    server_tokens off;

    location /koel {
        proxy_http_version 1.1;
        proxy_pass http://koel;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Script-Name /koel;

        gzip            on;
        gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
        gzip_comp_level 9;

        location ~ /koel/media/ {
            internal;
            # A 'X-Media-Root' should be set to media_path settings from upstream
            alias       $upstream_http_x_media_root;
            #access_log /var/log/nginx/koel.access.log;
            #error_log  /var/log/nginx/koel.error.log;
        }
        location ~ \.php$ {
            #try_files $uri $uri/ /index.php?$args;

            fastcgi_param     PATH_INFO $fastcgi_path_info;
            fastcgi_param     PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param     SCRIPT_FILENAME $document_root$fastcgi_script_name;
            # PHP7
            fastcgi_pass              unix:/var/run/php/php7.0-fpm.sock;
            # PHP5
            #fastcgi_pass             unix:/var/run/php5-fpm.sock;
            fastcgi_index             index.php;
            fastcgi_split_path_info   ^(.+\.php)(/.+)$;
            fastcgi_intercept_errors  on;
            include                   fastcgi_params;
        }
    }
}

Docker-compose.yml

version: '3'

services:
  koel:
    image: hyzual/koel
    depends_on:
      - database
    ports:
      - "${PORT}:80"
    environment:
      - DB_CONNECTION=pgsql
      - DB_HOST=database
      - DB_USERNAME=koel
      - DB_PASSWORD=password
      - DB_DATABASE=koel
    volumes:
      - "${MOUNT_MUSIC}:/music"
      - "${MOUNT_COVERS}:/var/www/html/public/img/covers"
      - "${MOUNT_INDEX}:/var/www/html/storage/search-indexes"
      - "${MOUNT_ENV}:/var/www/html/.env"
  database:
    image: postgres:13
    volumes:
      - "${MOUNT_SQL}:/var/lib/postgresql/data"
    environment:
      - POSTGRES_DB=koel
      - POSTGRES_USER=koel
      - POSTGRES_PASSWORD=password

koel.env

APP_URL=https://example.com/koel
FORCE_HTTPS=true
APP_KEY=key

Docker-compose.env

# Port to expose HTTP service
# Set to 127.0.0.1:port if you wish to reverse-proxy the docker's port,
# otherwise the port specified here will be publicly accessible
PORT=127.0.0.1:5050

# Directory to store koel img covers
MOUNT_COVERS=/var/local/koel/covers

# Directory to store koel music
MOUNT_MUSIC=/var/local/koel/music

# Directory to store koel search index
MOUNT_INDEX=/var/local/koel/index

# Directory to store database files
MOUNT_SQL=/var/local/koel/sql

# Koel .env file
MOUNT_ENV=./koel.env

Environment

  • Koel version v5.1.8
  • OS: Ubuntu 20.04
  • Browser: Firefox
  • PHP version Latest as of writing
  • Node version Latest as of writing
@phanan phanan transferred this issue from koel/koel Dec 30, 2021
@phanan
Copy link
Member

phanan commented Dec 30, 2021

Please report in the right repo. Transferred for you.

@Hyzual
Copy link
Collaborator

Hyzual commented Dec 30, 2021

@phanan thanks for the transfer, didn't know one can do that, neat feature :).

@INNKCake From what I can gather, it looks like you should be using APP_URL var like you said you used. By any chance, does it make a difference if you provide APP_URL through the environment section in Docker-compose.yml ?
Also, koel uses a lot of caching, does it help if you run php artisan cache:clear in the koel container ? I'm thinking that maybe the paths to the assets is somehow cached and it would still give you the default despite APP_URL having changed.

@INNKCake
Copy link
Author

INNKCake commented Jan 1, 2022

@phanan thank you for the transfer.

@Hyzual I'll try your suggestions.

@xeruf
Copy link

xeruf commented Mar 9, 2022

I apparently got it to work with a similar setup now, did you get this fixed @INNKCake ?

@INNKCake
Copy link
Author

I apparently got it to work with a similar setup now, did you get this fixed @INNKCake ?

@xeruf Sadly, no. Same problems. Tried a coulpe of times and desided to leave it for now.
Can you share your koel/nginx configuration that works? Would be great!

@xeruf
Copy link

xeruf commented Mar 14, 2022

Nginx config:

server {
  listen 80;
  listen [::]:80;
  server_name koel.example;
  location / { return 301 https://$host$request_uri; }
}

server {
  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  server_name koel.example;
  ssl_certificate /etc/letsencrypt/live/koel.example/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/koel.example/privkey.pem;

  location / {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;

    proxy_pass              http://localhost:1380/;

    proxy_read_timeout      600s;
    proxy_send_timeout      600s;
  }
}

docker-compose.mysql.yml

version: '3'

services:
  koel:
    image: hyzual/koel
    depends_on:
      - database
    ports:
      - 1380:80
    environment:
      - DB_CONNECTION=mysql
      - DB_HOST=database
      - DB_USERNAME=koel
      - DB_PASSWORD=PASS
      - DB_DATABASE=koel
    volumes:
      - /srv/funkwhale/data/music:/music
      - covers:/var/www/html/public/img/covers
      - search_index:/var/www/html/storage/search-indexes
      - ./koel.env:/var/www/html/.env

  database:
    image: mysql/mysql-server:5.7
    volumes:
      - db:/var/lib/mysql
    environment:
      MYSQL_DATABASE: koel
      MYSQL_USER: koel
      MYSQL_PASSWORD: PASS
      MYSQL_ROOT_PASSWORD: PASS

volumes:
  db:
    driver: local
  music:
    driver: local
  covers:
    driver: local
  search_index:
    driver: local

koel.env

APP_URL=https://koel.example
FORCE_HTTPS=true

Note that I am using the music collection from Funkwhale as that is what I tried before and am now using Ampache as I realized that its feature-richness far surpasses the modern interface of Koel for my case. But all three are still running perfectly well :)

I actually initially had a blank response due to a misconfigured DNS entry 🤦‍♂️ and then I had forgotten to run the initialization.

@viasux
Copy link

viasux commented Mar 14, 2023

I'd also prefer to reverse proxy koel, so certs & such are handled by caddy like everything else on my system. However, I can't even seem to figure out how I'm supposed to set the domain name/cert or even serve koel in any capacity. After successfully installing, I tried php artisan serve, but reverse-proxying localhost:8000 (which is where it said the server was being served), does nothing. I'd assume this is because it's on that port inside of the docker container, but there doesn't appear to be any mention of how else you're supposed to serve it.

also, what is koel.env and Docker-compose.env, I don't have those in the dir from the official release.

@viasux
Copy link

viasux commented Mar 18, 2023

Oh my god this needs to be placed or at least linked to chronologically i read this so many times and skipped it every time because i thought it was for manual installs only

https://github.com/koel/docker#useful-environment-variables

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

5 participants