YoutubeDL-Material icon indicating copy to clipboard operation
YoutubeDL-Material copied to clipboard

[BUG] - Slight correct to documentation for the reverse proxy for nginx subfolder

Open DuckieNukeEm opened this issue 2 years ago • 4 comments

Describe the bug In the documentation for a reverse proxy with a subfolder, it currenlty reads as:

location ~/ytdl(.*)$ {
	rewrite /ytdl/(.*) /  break;
	proxy_pass http://example.com:8998;
}
	
location /api/ {
	proxy_pass http://example.com:8998;
}

That partially works and yield a white screen when in effect. To actually get the full app, we need to add a $1 after the slash.

location ~/ytdl(.*)$ {
	rewrite /ytdl/(.*) /$1  break;
	proxy_pass http://example.com:8998;
}
	
location /api/ {
	proxy_pass http://example.com:8998;
}

the rewwrite of /ytdl/(.*) / break writes everything after to ytdl/ straight to /, which doesn't work (IE ytdl/#/home gets mapped to /), what we want is to keep everything after the slash (IE we want /ytdl/#/home to get mapped to /#/home), hence the need for $1 after the rewrite

DuckieNukeEm avatar Nov 09 '22 13:11 DuckieNukeEm

I adapted the config from this comment and all is working well. I could not get either of the above configs to work.

  location /ytdl {
    return 301 $scheme://$host/ytdl/;
  }

  location ^~ /ytdl/ {
    proxy_pass http://127.0.0.1:8998;
    proxy_redirect  off;
    proxy_set_header Referer '';
    proxy_set_header Host 127.0.0.1:8998;
    rewrite /ytdl(.*) $1 break;
  }

  location ^~ /ytdl/api/ {
    proxy_pass http://127.0.0.1:8998;
  }
  
  location ^~ /api/ {
    proxy_pass http://127.0.0.1:8998;
  }

dd900 avatar Nov 24 '22 20:11 dd900

For me, the below config works (header access control allowed, otherwise only html code is displayed)

location /ytdl {
    return 301 /ytdl/;
  }

  location ^~ /ytdl/ {
    add_header Access-Control-Allow-Origin *;
    proxy_pass http://127.0.0.1:8998;
    proxy_redirect  off;
    proxy_set_header Referer '';
    proxy_set_header Host 127.0.0.1:8998;
    rewrite /ytdl(.*) $1 break;
  }

  location ^~ /ytdl/api/ {
    proxy_pass http://127.0.0.1:8998;
  }

  location ^~ /api/ {
    proxy_pass http://127.0.0.1:8998;
  }

jaganathsamal avatar May 08 '23 19:05 jaganathsamal

Hi! I came here after some clicks and the configuration suggested by @DuckieNukeEm works for me! Why the documentation has not been updated yet? I can do a PR if needed @Tzahi12345

thegabriele97 avatar May 09 '23 18:05 thegabriele97

For me, the below config works (header access control allowed, otherwise only html code is displayed)

location /ytdl {
    return 301 /ytdl/;
  }

  location ^~ /ytdl/ {
    add_header Access-Control-Allow-Origin *;
    proxy_pass http://127.0.0.1:8998;
    proxy_redirect  off;
    proxy_set_header Referer '';
    proxy_set_header Host 127.0.0.1:8998;
    rewrite /ytdl(.*) $1 break;
  }

  location ^~ /ytdl/api/ {
    proxy_pass http://127.0.0.1:8998;
  }

  location ^~ /api/ {
    proxy_pass http://127.0.0.1:8998;
  }

I am not a nginx expert but maybe you have add_header X-Content-Type-Options nosniff; enabled somewhere

thegabriele97 avatar May 09 '23 18:05 thegabriele97