alexjustesen / speedtest-tracker

Speedtest Tracker is a self-hosted internet performance tracking application that runs speedtest checks against Ookla's Speedtest service.
https://speedtest-tracker.dev/
MIT License
2.88k stars 106 forks source link

url is wrong when using https and non-standard port such as 8443 at same time #1685

Open lz37 opened 2 months ago

lz37 commented 2 months ago

Describe the bug url is wrong when using https and non-standard port such as 8443 at same time

To Reproduce when setting https and non-standard port, the request of css file is still 443, FORCE_HTTPS doesn't even work. I use k8s, and default port of Nginx Ingress is 8443(in china poeople usually can't use 80 and 443 personally)

Expected behavior just like graphs

image

Environment (please complete the following information):

Screenshots image

Logs If applicable, check the logs for any error that might of occurred.

Additional context

apiVersion: v1
kind: Service
metadata:
  name: speedtest
spec:
  ports:
    - name: speedtest
      port: 80
      protocol: TCP
  selector:
    app: speedtest
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: speedtest
  labels:
    app: speedtest
spec:
  replicas: 1
  selector:
    matchLabels:
      app: speedtest
  template:
    metadata:
      labels:
        app: speedtest
    spec:
      containers:
        - name: speedtest
          image: lscr.io/linuxserver/speedtest-tracker:latest
          resources:
            limits:
              cpu: "0.5"
              memory: 1024Mi
            requests:
              cpu: "0.02"
              memory: 16Mi
          ports:
            - containerPort: 80
          env:
            - name: PUID
              value: "1000"
            - name: PGID
              value: "1000"
            - name: DB_CONNECTION
              value: pgsql
            - name: SPEEDTEST_SCHEDULE
              value: "0,30 * * * *"
            - name: DB_HOST
              value: postgres
            - name: DB_PORT
              value: "5432"
            - name: DB_DATABASE
              value: speedtest
            - name: DB_USERNAME
              value: xxxxxx
            - name: DB_PASSWORD
              value: xxxxxxx
            - name: DISPLAY_TIMEZONE
              value: "Asia/Shanghai"
            - name: TZ
              value: "Asia/Shanghai"
            - name: PRUNE_RESULTS_OLDER_THAN
              value: "365"
            - name: APP_KEY
              value: xxxxxx
            - name: APP_URL
              value: https://xxxxxx:8443
            - name: FORCE_HTTPS
              value: "true"
            - name: APP_TIMEZONE
              value: "Asia/Shanghai"
            - name: APP_LOCALE
              value: "zh-CN"
          volumeMounts:
              - name: localtime
                readOnly: true
                mountPath: /etc/localtime
              - mountPath: /config
                name: speedtest-tracker
      volumes:
        - name: localtime
          hostPath:
            type: File
            path: /etc/localtime
        - name: speedtest-tracker
          persistentVolumeClaim:
            claimName: nfs-speedtesttracker-config-pvc
---
# ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: speedtest
  labels:
    name: speedtest
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "dnspod"
    nginx.ingress.kubernetes.io/proxy-body-size: "10m"
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - xxxxxx
      secretName: xxxxx
  rules:
    - host: xxxxx
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: speedtest
                port:
                  number: 80
adrianmusante commented 2 months ago

I had a similar issue where the URLs for the page resources were being generated incorrectly. To resolve this, I did not use the FORCE_HTTPS variable. Instead, I added the ASSET_URL variable and set it to the same value as APP_URL.

lz37 commented 2 months ago

I had a similar issue where the URLs for the page resources were being generated incorrectly. To resolve this, I did not use the FORCE_HTTPS variable. Instead, I added the ASSET_URL variable and set it to the same value as APP_URL.

Oh, thank you very much!

svenvg93 commented 2 months ago

@lz37 please let us know if it resolves your issue. Then I make sure it will added to the documentation. and if it resolves it please close the issue ☺️

lz37 commented 2 months ago

@svenvg93 it works on asset but the navigation is still use the standard port. For example, https://xxx:8443/admin/login succeed and navigate to https://xxx/admin so i have to add the port manually every time. It is a little problem however.

svenvg93 commented 2 months ago

Don't know anything about the k8s and the ingress. Im afraid I cant be of much help with this :(

lz37 commented 2 months ago

Generally speaking this is an nginx issue, not a k8s issue

alnviana commented 2 months ago

I don't think it's a problem with k8s or Nginx, but with the application itself. Below are the reasons why I think so.

I'm trying to do something very similar, but I'm using Docker, with Nginx on a different port using HTTPS and a custom path: https://fqdn:2443/speedtest-tracker/. When I access this address, I get a redirect (HTTP status code 302) with the destination: https://fqdn/admin/login When I access the address including the login path (https://fqdn:2443/speedtest-tracker/admin/login), I am not redirected, the login screen loads successfully (HTTP status code 200). After that, if I try to log in, I get an error message (405 Method Not Allowed) and I can't do anything else.

Just to let you know, I also had a problem with the login screen assets before, but setting the APP_KEY and ASSET_URL variables to the full address (https://fqdn:2443/speedtest-tracker/) solved it. Thanks. :) I'm currently looking to see if there are any other parameters that might help...

Edit: I think it might be related: https://github.com/alexjustesen/speedtest-tracker/issues/1563

svenvg93 commented 1 month ago

Hi All,

Would it be possible to share which proxy you are using and the configuration. So I can try to replicate the problem. So far we haven't seen any problems when using Cloudflare tunnels or Traefik as a proxy.