🇺🇦 We stand with Ukraine! 🇺🇦

X-Script-Name not respected

What is the problem?

When using nginx reverse proxy with a X-Script-Name header, the redirect to the login page works fine but then the web page requests that follow do not respect that header.

What did you already try to solve it?

Adding random other headers that shouldn't and didn't affect the problem.

Have you tried running in safe mode?

Yes

Did running in safe mode solve the problem?

No

Systeminfo Bundle

octoprint-systeminfo-20220513165258.zip (24.7 KB)

Additional information about your setup

OctoPrint Version 1.7.3
OctoPi Version 0.18.0, running on Raspberry Pi 3 Model B Rev 1.2
Prusa mk3s
Firmware: stock
browser: chrome
operating system: windows 10
nginx version: nginx/1.14.0 (Ubuntu)


Problem details ...

Nginx setup ...

  location /prusa/ {
    add_header X-Script-Name /prusa;
    rewrite ^/prusa/(.*) /$1 break; #strip /prusa from url
    proxy_pass http://192.168.1.205/;
  }

I browse to http://mydomain/prusa

192.168.1.106 - - [13/May/2022:17:06:33 -0700] 
"GET /prusa/ HTTP/1.1" 302 331 "-" 
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/101.0.4951.54 Safari/537.36"

It redirects to login correctly using the X-Script-Name /prusa

192.168.1.106 - - [13/May/2022:17:06:33 -0700] 
"GET /prusa/login/?redirect=%2F%3F
&permissions=STATUS%2CSETTINGS_READ HTTP/1.1" 
200 1145 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/101.0.4951.54 Safari/537.36"

But then every request after that is ignoring X-Script-Name. This is the first

192.168.1.106 - - [13/May/2022:17:06:33 -0700] 
"GET /static/css/bootstrap.min.css HTTP/1.1" 
404 209 "http://mydomain.com/prusa/login/
?redirect=%2F%3F&permissions=STATUS%2CSETTINGS_READ" 
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/101.0.4951.54 Safari/537.36"

I said

I have discovered that nginx is not sending the header after 
that redirect so my problem appears to be in my nginx 
setup.  So you can consider this question closed unless 
I say otherwise.

but I was confused and looking in the wrong place. The redirect response returned this to the browser ...

Connection: keep-alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Sat, 14 May 2022 00:42:23 GMT
Server: nginx/1.14.0 (Ubuntu)
< snip >
Set-Cookie: 
Path=/
Transfer-Encoding: chunked
Vary: Cookie
X-Clacks-Overhead: GNU Terry Pratchett
X-Content-Type-Options: nosniff
X-Frame-Options: sameorigin
X-Robots-Tag: noindex, nofollow, noimageindex
X-Script-Name: /prusa

So nginx did tell the octoprint web page to use the X-Script-Name in the following requests. Is this not right?

Compare your nginx configuration to the one in the examples below, there is a section for hosting it at a different location than the server route.