openspeedtest / Docker-Image

OpenSpeedTest Docker Image
124 stars 26 forks source link

Support for reverse proxy path based routing #9

Closed ThorpeJosh closed 1 year ago

ThorpeJosh commented 1 year ago

Hi, Thanks for the awesome tool!

I tried putting this behind a reverse proxy so that I can access it at the path https://my.domain/speedtest. I added a traefik stripprefix middleware that strips the /speedtest from the path and the page loads correctly; however as soon as I click start I get a 'Network Error' as it seems that my browser is attempting to reach https://my.domain/upload?..... but for it to route through my reverse proxy correctly it needs to be https://my.domain/speedtest/upload?.... instead.

I have a lot of services and I want to setup this speedtest service on many servers so want to avoid creating a new domain for each instance. I do path based routing for many other applications, most work, some don't. The two ways applications seem to support path based routing is to use relative paths and not absolute, or by having an environment variable that allows me to set the application base path, eg. BASE=/speedtest with the default as BASE=/.

Would this be something you could support?

Thanks, Josh

openspeedtest commented 1 year ago

I recently took a test at https://somedot.com/test/. The download and upload processes worked correctly. The app requested the URL https://somedot.com/test/downloading for downloading and https://somedot.com/test/upload for uploading. If you can either post the URL or send it to support@openspeedtest.com, that would be helpful.

openspeedtest commented 1 year ago

Or you can edit index.html https://github.com/openspeedtest/Speed-Test/blob/main/index.html#L51

  var openSpeedTestServerList = [
        {"ServerName":"Home", "Download":"https://somedot.com/test/downloading", "Upload":"https://somedot.com/test/upload", "ServerIcon":"DefaultIcon"}
      ];

Irrespective of the domain name, it will request for the exact same address for both download and upload operations.

ThorpeJosh commented 1 year ago

I recently took a test at https://somedot.com/test/.

I don't understand. I tried this and got an nginx 404 since the path /test doesn't exist. It would only work on the / root path

openspeedtest commented 1 year ago

Check this https://vishnu.pro/test/ Also try the second option I posted.

ThorpeJosh commented 1 year ago

How'd did you get that to work? Are you using the official docker image?

In the context of using the docker image, the second option is very hacky. Can that be made an environment variable so that I don't have to build a custom image?

openspeedtest commented 1 year ago

That was not a docker image. Now I tested docker image and it's working fine.

        - "traefik.enable=true"
        - "traefik.http.routers.openspeedtest.rule=Host(`home.vishnu.pro`) && PathPrefix(`/test/`)"
        - "traefik.http.routers.openspeedtest.middlewares=strip-prefix"
        - "traefik.http.services.openspeedtest.loadbalancer.server.port=3000"
        - "traefik.http.middlewares.strip-prefix.stripprefix.prefixes=/test/"
openspeedtest commented 1 year ago

Like I mentioned here https://github.com/openspeedtest/Speed-Test/issues/4#issuecomment-1229157193 you may need to add limit. If the performance tradeoff is acceptable, you can continue using configuration with limit. Otherwise, consider moving the "openspeedtest" service to a separate subdomain for better performance and isolation.

        - "traefik.enable=true"
        - "traefik.http.routers.openspeedtest.rule=Host(`lol.vishnu.pro`) && PathPrefix(`/test/`)"
        - "traefik.http.routers.openspeedtest.middlewares=strip-prefix,limit"
        - "traefik.http.services.openspeedtest.loadbalancer.server.port=3000"
        - "traefik.http.middlewares.strip-prefix.stripprefix.prefixes=/test/"
        - "traefik.http.middlewares.limit.buffering.maxRequestBodyBytes=35000000"
        - "traefik.http.middlewares.limit.buffering.memRequestBodyBytes=35000000"
        - "traefik.http.middlewares.limit.buffering.maxResponseBodyBytes=35000000"
        - "traefik.http.middlewares.limit.buffering.memResponseBodyBytes=35000000"
ThorpeJosh commented 1 year ago

That is exactly the traefik config I was using. After pulling the latest image (released a few days ago), it started to work correctly.

Thanks