ansemjo / speedtest-plotter

running scheduled speedtests inside docker and plotting the results with gnuplot
MIT License
60 stars 12 forks source link

Possibility for reverse proxy adoption / Change base url #76

Closed mr-honest closed 2 years ago

mr-honest commented 2 years ago

Hi.

Would it be too much work for you to allow for reverse proxy, so I can use subfolder directive on nginx?

So instead of http://domain.com:8000, I can access by http://domain.com/speedtest

I did try different rewrite rules in nginx, and the closest i got was this:

location /speedtest {
        rewrite ^/speedtest(.*)$ $1 break;
        proxy_pass http://speedtest:8000;
    }

However this will not load the svg graphics.

ansemjo commented 2 years ago

I think that all you need to change is add a trailing slash to your proxy_pass directive:

location /speedtest {
  rewrite ^/speedtest(.*)$ $1 break;
  proxy_pass http://speedtest:8000/;
}

I'm not sure though, that's off the top of my head. There is definitely a trick to do this in nginx without needing to change speedtest-plotter in any way.

mr-honest commented 2 years ago

Hi, I did also try your method, and still the vector graphic would not load. I have tried for many hours, and finally it seemed the solution was to change the backend, to allow for url rebase.

ansemjo commented 2 years ago

Indeed, that's because the form action and the SVG in the page were using a leading slash. Removing that / changing it to . enabled a reverse proxy with a subdirectory location. See diff in b881e48383419c0b80beece7b0acd91dc30da11d.

I tested this locally with an nginx configuration that did not even need a rewrite directive:

location /speedtest/ { # trailing slash here seems to be important, too
  proxy_pass http://speedtest:8000/;
}

edit: you'll need to wait until the CI build is finished and re-pull the image.