Forver HTTP 404 when local run by binary

Hello,

I run traefik on a local machine.
The dashboard works, but I can't access my application.
I always get HTTP 404 when I try to send a request to the application.
I run everything on one local machine. Without docker, k8s and etc.

What am I doing wrong?

Stack:

  1. Ubuntu 22.10
  2. Traefik v3.2.3 (binary file from github repo )
  3. Simple golang app

Source code of the application:

package main

import (
	"log"
	"net/http"
)

func responseURLHandler(w http.ResponseWriter, r *http.Request) {
	log.Printf("Host: %s | Method: %s | Path: %s\n", r.Host, r.Method, r.URL)
}

func main() {
	http.HandleFunc("/", responseURLHandler)
	log.Println("starting....")
	http.ListenAndServe(":8000", nil)
	log.Println("stopping....")
}

Configfile traefik

#############################
#
# Configuration for Traefik v2.
#
#############################


#############################
# Global configuration
#############################
global:
  checkNewVersion: true
  sendAnonymousUsage: true


#############################
# Traefik UI
#############################
serversTransport:
  insecureSkipVerify: true


#############################
# Traefik logs configuration
#############################
log:
  level: INFO
  # format: json


#############################
# Access logs configuration
#############################
accessLog: {}
  # Sets the file path for the access log. If not specified, stdout will be used.
  # Intermediate directories are created if necessary.
  #
  # Optional
  # Default: os.Stdout
  #
#  filePath: /path/to/log/log.txt

  # Format is either "json" or "common".
  #
  # Optional
  # Default: "common"
  #
#  format: json


#############################
# API and dashboard configuration
#############################

# Enable API and dashboard
#
# Optional
#
api:
  # Enable the API in insecure mode
  #
  # Optional
  # Default: false
  #
  insecure: true

  # Enabled Dashboard
  #
  # Optional
  # Default: true
  #
#  dashboard: false


#############################
# EntryPoints configuration
#############################
entryPoints:
  web:
    address: ":8888"
    asDefault: true

http:
  routers:
    app-router:
      service: app-service
      entryPoints:
        - "web"

  services:
    app-service:
      loadBalancer:
        servers:
          - url: http://localhost:8000/

Test run

Run app

go run main.go

Run traefik

traefik --configfile=traefik_lab.yaml

Send request

curl http://localhost:8888/api/xxx/111

Result: Traefik accesslog

::1 - - [26/Dec/2024:12:09:32 +0000] "GET /api/xxx/111 HTTP/1.1" 404 19 "-" "-" 1 "-" "-" 0ms

Managed to solve the problem.

The problem is that part of traefik ignored the directive: http.
The problem is solved by specifying the provider and storing the settings in a separate file.
And in general, traefik sometimes does not signal about incorrect configurations, but simply ignores them.

Solution

Dir structure:

tree .

.
├── app.yaml
├── main.go
└── traefik.yaml

File traefik.yaml :

################################################################
#
# Configuration for Traefik v2.
#
################################################################


################################################################
# Global configuration
################################################################
global:
  checkNewVersion: true
  sendAnonymousUsage: true


################################################################
# Traefik UI
################################################################
serversTransport:
  insecureSkipVerify: true


################################################################
# Traefik logs configuration
################################################################
log:
  level: INFO
  # format: json


################################################################
# Access logs configuration
################################################################
accessLog: {}
  # Sets the file path for the access log. If not specified, stdout will be used.
  # Intermediate directories are created if necessary.
  #
  # Optional
  # Default: os.Stdout
  #
#  filePath: /path/to/log/log.txt

  # Format is either "json" or "common".
  #
  # Optional
  # Default: "common"
  #
#  format: json


################################################################
# API and dashboard configuration
################################################################

# Enable API and dashboard
#
# Optional
#
api:
  # Enable the API in insecure mode
  #
  # Optional
  # Default: false
  #
  insecure: true

  # Enabled Dashboard
  #
  # Optional
  # Default: true
  #
#  dashboard: false


################################################################
# EntryPoints configuration
################################################################
entryPoints:
  web:
    address: ":8888"

providers:
  file:
    filename: app.yaml

File app.yaml :

http:
  routers:
    my-router:
      rule: "Host(`localhost`)"
      service: my-service
      entryPoints:
        - web

  services:
    my-service:
      loadBalancer:
        servers:
          - url: "http://localhost:8000"

Run traefik:

traefik --configfile=traefik.yaml

It's work.

Also, you can specify not a specific configuration file, but a directory with configurations.

Set in traefik.yaml

providers:
  file:
    directory: "/path/to/dynamic/conf"