Webmin behind HAProxy - Error: 502 Bad Gateway

OS type and version Ubuntu 20.04.4
Webmin version 2.000
Authentic Theme version 20.00

I have webmin setup behind HA Proxy I keep getting the following error. This same error pops-up when webmin is setup behind an apache proxy also. This seams to be a visual bug not really affecting my usability of webmin. On the main page the “Stats History” never loads looks like it’s associated with this. Is there a way to turn this feature off or can someone provide the code fix for this?

  • stats.cgi?xhr-stats=general

I have read lots of forums and blogs about this or similar error’s with webmin and it being hosted behind a proxy without finding a solid answer. Running webmin behind a proxy appears to be a normal practice done by lots of people may people getting it done without a problem.

There is this post from 2017 referencing the same error. May or may not be ralated.
Theme continually requests stats.cgi even when not on the system information page · Issue #958 · webmin/authentic-theme · GitHub


It works for me behind proxy.

Can you please show exact error message that you’re seeing? Also, what is your proxy configuration looks like?

Exact error that shows on the screen

  • Error: 502 - Bad Gateway - /stats.cgi?xhr-stats=general

ha proxy config
frontend http-in
mode http
bind ssl crt /etc/ssl/certs/haproxycert.pem
redirect scheme https if !{ ssl_fc }
option forwardfor
use_backend webmin_http if { hdr_dom(Host) -i servermanagement.example.com }

backend webmin_http
mode http
http-request set-header X-Forwarded-Port %[dst_port]
http-request set-header X-Forwarded-Proto https if { ssl_fc }
http-response replace-value Location (.):. \1
balance source
option httpclose
option forwardfor
server dnsc webmin.example.com:10000 check

Perhaps, you’re trying to connect to http version of Webmin instance rather than https?

I personally don’t use HAProxy and therefore not aware about specifics, but it seems that other users successfully setup Webmin behind HAProxy.

If you are just passing through to a backend Webmin server, maybe try using the port number as the rule:

frontend myfrontend

use_backend webmin if { dst_port 10000 }

backend webmin
  server server2
1 Like