[GH-ISSUE #255] Base URL / Reverse proxy issue, Last.fm callback #189

Closed
opened 2026-02-26 02:32:23 +03:00 by kerem · 8 comments
Owner

Originally created by @Beanow on GitHub (Mar 2, 2016).
Original GitHub issue: https://github.com/koel/koel/issues/255

Previously I've submitted some PRs and suggestions regarding this on v1.x.
I've upgraded to v2.1.0 and the issue still persists.

To reproduce:

  1. Configure a reverse proxy setup.
  2. Go to your profile preferences & settings.
  3. Initiate a Last.fm (re-)connect.

Expected result:

  • The callback URL provided to Last.fm is the external URL.

Actual result:

  • The callback URL provided to Last.fm is the internal URL.

In my case the external URL is http://music.example.com/ and the internal one is http://10.10.10.123/.
The reverse proxy is an apache one configured with:

<VirtualHost *:80>
        ServerName music.example.com
        ProxyPass / http://10.10.10.123/
        ProxyPassReverse / http://10.10.10.123/
        ProxyPassReverseCookieDomain 10.10.10.123 music.example.com
</VirtualHost>

One solution that worked very effectively for me was #165 which added a middleware and configuration value to support X-Forwarded-* for trusted proxies. It allowed me to add this to my .env file to fix the issue.

# For load balancers and reverse proxies.
# Set this to an IP or CIDR range (192.168.1.10 or 192.168.1.0/24).
# For more details see http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html
TRUSTED_PROXY=10.10.10.0/24
Originally created by @Beanow on GitHub (Mar 2, 2016). Original GitHub issue: https://github.com/koel/koel/issues/255 Previously I've submitted some PRs and suggestions regarding this on v1.x. I've upgraded to v2.1.0 and the issue still persists. To reproduce: 1. Configure a reverse proxy setup. 2. Go to your profile preferences & settings. 3. Initiate a Last.fm (re-)connect. Expected result: - The callback URL provided to Last.fm is the external URL. Actual result: - The callback URL provided to Last.fm is the internal URL. In my case the external URL is http://music.example.com/ and the internal one is http://10.10.10.123/. The reverse proxy is an apache one configured with: ``` <VirtualHost *:80> ServerName music.example.com ProxyPass / http://10.10.10.123/ ProxyPassReverse / http://10.10.10.123/ ProxyPassReverseCookieDomain 10.10.10.123 music.example.com </VirtualHost> ``` One solution that worked very effectively for me was #165 which added a middleware and configuration value to support X-Forwarded-\* for trusted proxies. It allowed me to add this to my `.env` file to fix the issue. ``` # For load balancers and reverse proxies. # Set this to an IP or CIDR range (192.168.1.10 or 192.168.1.0/24). # For more details see http://symfony.com/doc/current/components/http_foundation/trusting_proxies.html TRUSTED_PROXY=10.10.10.0/24 ```
kerem closed this issue 2026-02-26 02:32:23 +03:00
Author
Owner

@phanan commented on GitHub (Mar 17, 2016):

Sorry for late reply. I'll try to find some time for the setup and test the issue.

<!-- gh-comment-id:198011316 --> @phanan commented on GitHub (Mar 17, 2016): Sorry for late reply. I'll try to find some time for the setup and test the issue.
Author
Owner

@DeviantEng commented on GitHub (Jun 7, 2016):

I'm not sure if this is relevant to Laravel 5, or not, but on other Laravel 4.x applications (specifically, https://github.com/twostairs/paperwork), I had to add 2 lines to the routes.php file:

URL::forceRootUrl('https://notes.domain.com');
URL::forceSchema('https');

URL::forceSchema('https'); was needed because my app ran locally as HTTP, but my reverse proxy (Nginx) terminated my https for me.

Again, not sure if any behavior changed in Laravel 5.x (koel is based on 5.x, right?), but I will be testing this out here soon.

I just got koel up and running on a CentOS 7 LXC with php7 and once I get my full library scanned, I will be testing it out with my reverse proxy setup.

<!-- gh-comment-id:224305058 --> @DeviantEng commented on GitHub (Jun 7, 2016): I'm not sure if this is relevant to Laravel 5, or not, but on other Laravel 4.x applications (specifically, https://github.com/twostairs/paperwork), I had to add 2 lines to the routes.php file: ``` URL::forceRootUrl('https://notes.domain.com'); URL::forceSchema('https'); ``` `URL::forceSchema('https');` was needed because my app ran locally as HTTP, but my reverse proxy (Nginx) terminated my https for me. Again, not sure if any behavior changed in Laravel 5.x (koel is based on 5.x, right?), but I will be testing this out here soon. I just got koel up and running on a CentOS 7 LXC with php7 and once I get my full library scanned, I will be testing it out with my reverse proxy setup.
Author
Owner

@DeviantEng commented on GitHub (Jun 7, 2016):

Follow up;

Just adding an entry in Nginx for reverse proxy did not working. Adding those above two lines into my routes.php, my reverse proxy is working as expected. Last.FM scrobbling is also working.

[root@koel Http]# pwd
/var/www/html/koel/app/Http
[root@koel Http]# head -10 routes.php
<?php

URL::forceRootUrl('https://koel.domain.com');
URL::forceSchema('https');

Route::get('/', function () {
    return view('index');
});

// Some backward compatibilities.
[root@koel Http]#

Nginx conf on my koel box:

[root@koel conf.d]# pwd
/etc/nginx/conf.d
[root@koel conf.d]# cat koel.conf
server {
    listen       80;
    server_name  localhost;
    set  $root_path '/var/www/html/koel';
    root  $root_path;
    index  index.php;

  location ~ /\. {
    deny  all;
  }

  location ~ /(app|bootstrap|config|database|resources|storage|tests|vendor|node_modules)/ {
    deny  all;
  }

  location /media/ {
    internal;
    alias  $upstream_http_x_media_root;
  }

  location / {
    try_files   $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_split_path_info       ^(.+\.php)(/.+)$;
    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;
  }
}

On my reverse proxy sever running Nginx (separate server):

[root@webproxy conf.d]# pwd
/etc/nginx/conf.d
[root@webproxy conf.d]# cat reverseproxy.conf
ssl_certificate         ssl/domain.com.crt;
ssl_certificate_key     ssl/domain.com.key;
ssl_dhparam             ssl/dhparam.pem;
ssl_session_timeout     5m;
ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers       on;
ssl_ciphers             AES256+EECDH:AES256+EDH:!aNULL;

server  {

  listen  80;
  server_name  *.domain.com;
  return 301 https://$host$request_uri;
}

server  {
  listen  443 ssl;
  server_name domain.com;
  ssl  on;
  location  / {
    return  404;
  }
}

[...]

server {
  listen  443 ssl;
  server_name koel.domain.com;
  ssl  on;
  location  / {
    proxy_pass  http://172.16.1.126/;
  }
}

Hope that can be of some help!

<!-- gh-comment-id:224335745 --> @DeviantEng commented on GitHub (Jun 7, 2016): Follow up; Just adding an entry in Nginx for reverse proxy did not working. Adding those above two lines into my routes.php, my reverse proxy is working as expected. Last.FM scrobbling is also working. ``` [root@koel Http]# pwd /var/www/html/koel/app/Http [root@koel Http]# head -10 routes.php <?php URL::forceRootUrl('https://koel.domain.com'); URL::forceSchema('https'); Route::get('/', function () { return view('index'); }); // Some backward compatibilities. [root@koel Http]# ``` Nginx conf on my koel box: ``` [root@koel conf.d]# pwd /etc/nginx/conf.d [root@koel conf.d]# cat koel.conf server { listen 80; server_name localhost; set $root_path '/var/www/html/koel'; root $root_path; index index.php; location ~ /\. { deny all; } location ~ /(app|bootstrap|config|database|resources|storage|tests|vendor|node_modules)/ { deny all; } location /media/ { internal; alias $upstream_http_x_media_root; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; 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; } } ``` On my reverse proxy sever running Nginx (separate server): ``` [root@webproxy conf.d]# pwd /etc/nginx/conf.d [root@webproxy conf.d]# cat reverseproxy.conf ssl_certificate ssl/domain.com.crt; ssl_certificate_key ssl/domain.com.key; ssl_dhparam ssl/dhparam.pem; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL; server { listen 80; server_name *.domain.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name domain.com; ssl on; location / { return 404; } } [...] server { listen 443 ssl; server_name koel.domain.com; ssl on; location / { proxy_pass http://172.16.1.126/; } } ``` Hope that can be of some help!
Author
Owner

@Porco-Rosso commented on GitHub (Jan 25, 2017):

@DeviantEng I have been having troubles getting https working as well. Now that routes.php is no longer there in Master, where should I insert URL::forceSchema('https'); ?
Thanks!

<!-- gh-comment-id:275192962 --> @Porco-Rosso commented on GitHub (Jan 25, 2017): @DeviantEng I have been having troubles getting https working as well. Now that routes.php is no longer there in Master, where should I insert `URL::forceSchema('https');` ? Thanks!
Author
Owner

@DeviantEng commented on GitHub (Jan 27, 2017):

@Porco-Rosso Sorry, but I don't have a clue. I ran into some other issues with Koel and just gave in and started using Plex for music.

<!-- gh-comment-id:275681448 --> @DeviantEng commented on GitHub (Jan 27, 2017): @Porco-Rosso Sorry, but I don't have a clue. I ran into some other issues with Koel and just gave in and started using Plex for music.
Author
Owner

@abba23 commented on GitHub (Apr 26, 2018):

If anyone else still has this problem, I got it working by adding the two lines like this:

$ head -5 routes/web.php 
<?php

URL::forceRootUrl('https://koel.example.com');
URL::forceScheme('https');

Note that the function URL::forceSchema is now called URL::forceScheme in the latest version.

<!-- gh-comment-id:384622764 --> @abba23 commented on GitHub (Apr 26, 2018): If anyone else still has this problem, I got it working by adding the two lines like this: ``` $ head -5 routes/web.php <?php URL::forceRootUrl('https://koel.example.com'); URL::forceScheme('https'); ``` Note that the function URL::forceSchema is now called URL::forceSchem**e** in the latest version.
Author
Owner

@xordspar0 commented on GitHub (Sep 10, 2018):

https://github.com/phanan/koel/issues/681 is a duplicate of this. Some users there suggest a configurable environment variable that allows forcing the base URL to use https://.

@phanan Do you think this is a good solution? Would you accept a patch that implements this?

<!-- gh-comment-id:420090850 --> @xordspar0 commented on GitHub (Sep 10, 2018): https://github.com/phanan/koel/issues/681 is a duplicate of this. Some users there suggest a configurable environment variable that allows forcing the base URL to use https://. @phanan Do you think this is a good solution? Would you accept a patch that implements this?
Author
Owner

@phanan commented on GitHub (May 18, 2019):

Closing via 488854127a.

<!-- gh-comment-id:493706040 --> @phanan commented on GitHub (May 18, 2019): Closing via 488854127aa933ea21ab0f97213c663e11ae95cb.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/koel-koel#189
No description provided.