Traefik, Nginx a trailing slash redirection switches to http and adds the port number

Hello… I’m a bit lost, searched the net a lot and did not succeed… my setup: K8s, Traefik as ingress controller/ reverse proxy, deployment with Nginx serving static files. So this is not Nginx as proxy but Traefik and Traefik forwards to Nginx. Traefik also handles TLS for Nginx (forwards http to https), so it talks to Nginx via http. The issue: when skipping the trailing /, the Nginx webserver does add the / and redirects, but turns the URL into http://server.com:8080/folder/ (http instead of https and adds port) - this gets stuck in the browser, of course. And I don’t think that Nginx is doing sth wrong here, I guess Traefik talks to it via http://server.com:8080. But is there an easy way to let Traefik redirect to the original URL - https://server.com/folder/? Not sure if this should be handled by Traefik or Nginx. Nginx itself does not know about the Ingress route, but if Traefik handles it, does the user see the http://server.com:8080 URL?

If nginx sends a redirect, then it should be the correct external URL. I am sure that can be configured.

Enable Traefik access log in JSON format to see OriginStatus and DownstreamStatus.

You can also use middleware to let Traefik do a redirect (doc).

I turned on the access log, do I need to specify format for Origin/ DownstreamStatus? What do I need to watch out for?

Traefik doc is your friend (link).

Thanks, so both Statuses are 301 but the redirection to http://server.com:8080 I do not see in the access log.

Status 301 means that the resource (page) is moved permanently to a new location. The client/browser should not attempt to request the original location but use the new location from now on.

So the redirect is cached by the browser.

That was it! I added

    port_in_redirect off;
    server_name_in_redirect off;
    absolute_redirect on;

to the http section in nginx.conf and clean up my browser cache. Then it worked.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.