Seite 1 von 1

Support for webinterface access via reverse proxy from different location than domain root doesn't work

Verfasst: Fr 12. Okt 2018, 15:52
von 1john2
Hi guys,
I try to enable MFBot v5.0.0.4 and webinterface.
I have few more web-based services which I host on domain.
I'd like to enable access to WebInterface using Nginx Location directive and proxypass directive.
I can't put webinterface to:
https://domain.tld/ - in this setup everything seems to be correct
I have to use:
https://domain.tld/sf/ - doesn't work correctly.

Environment:
OpenVZ based container with latest Centos 7.5 as a host.
Docker container (version 1.10.3 due compatilibty reasons with OpnVZ kernel) and latest Centos 7.5 userspace for MFBot and webinterface.
Nginx version:
Version : 1.14.0
Release : 1.el7_4.ngx
Relevant part of Nginx.conf:
location /sf {
return 301 /sf/;
}

location /sf/ {
proxy_pass http://127.0.0.1:8050/; #$my
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Strict-Transport-Security "max-age=0;";
proxy_http_version 1.1;
}

Webinterface and MFBot run in docker container.
Communication with webinterface from docker container is mapped to localhost:8050 as you can see in nginx.conf.

Steps to reproduce:
1) (optional) start docker container
2) start mfbot with valid Acc.ini
3) start webinterface: python3.6 /usr/local/src/webinterface/MainProgram.py --remoteU=FP9D --remoteP=udoYdi --webU=Q8O0 --webP=iUerOJ
NOTE: password are generated, remoteU and remoteP is configured in Acc.ini correctly
4) check netstat that webinterface is binded correctly:
netstat -ant | grep 8050
tcp 0 0 127.0.0.1:8050 0.0.0.0:* LISTEN
5) Try to access
https://domain.tld/sf/
In error.log you can see:
2018/10/12 13:39:58 [error] 22870#22870: *3662 open() "/var/www/_dash-update-component" failed (2: No such file or directory), client: u.x.y.z, server: domain.tld, request: "POST /_dash-update-component HTTP/1.1", host: "domain.tld", referrer: "https://domain.tld/Account
6) I was able to do few changes in app.py and MainProgram.py so webinterface mostly works.
a) I added those lines )L30-L34) in app.py:
app.config.update({$
# remove the default of '/'$
'routes_pathname_prefix': '',$
# remove the default of '/'$
'requests_pathname_prefix': ''$
})$
NOTE: with them first page loaded, nothing else worked.
b) I removed initial "/" in links. Later I will publish git repo with details. Paths are no longer handled as absolute ones and nginx proxy_pass them correctly
For example lines 43-44 from app.py:
html.Th(dcc.Link('Account Overview', href='Overview')) # here you had "/" only after removal with empty href it doesn't work correctly.
html.Th(dcc.Link('Account Details', href='Account')),$
I changed logic in MainProgram.py:
def display_page(pathname):$
logUtil.log(1,"Pathname: %s" % pathname)$
if pathname.split('/')[-1] == 'Account':$
return AccountDetails.getLayout()$
elif pathname.split('/')[-2] == 'Account':$
return AccountDetails.getLayout(pathname.split('/')[-1])$
elif pathname.split('/')[-1] == 'Bot_Log':$
return BotLog.getLayout()$
elif pathname.split('/')[-1] == 'Settings':$
return BotSettings.getLayout()$
elif pathname.split('/')[-1] == 'AccountSettings':$
return AccountSettings.getLayout()$
else:$
return AccountOverview.getLayout()$
$

NOTE: Now, I can click buttons Account details/overview/bot settings and they work
Problem: I'm not able to update POST requests.
If I hover over account name(USER@WORLD) on Overview page I can see link:
https://domain.tld/Account/USER@WORLD'
Insteaf of:
https://domain.tld/sf/Account/USER@WORLD'

Can you please help me to fix this issue?

Many thanks for your work guys!