18

I'd like to serve static ressources such as images, js bundles, html pages... with Traefik like I was able to do with nginx

# nginx config
server {
    root /www/data;

    location ~ \.js {
        root /www/bundles;
    }
}

Many thanks Cheers

2 Answers 2

40

Traefik doesn't serve static files (it's a not a web server it's a reverse proxy/load balancer).

You must use a container, which contains a web server with your files.

2
  • So what is solution when I want to serve static files with nginx? 1) create 1 traefik for ssl 2) create nginx for serving static ? Oct 31, 2018 at 13:15
  • I would like to knock out nginx entirely for our django deploys. I thought Traefik might be a nice replacement there.
    – Alper
    Oct 25, 2019 at 8:34
15

To extend the answer related to how files can be served:

If you are already serving files with nginx and want to migrate to Traefik you can still have nginx serving static files behind Traefik. I do this myself in hobby projects running docker standalone on a VM.

The best way is probably still to use containers/buckets such as S3 or Swift for static files as it will offload the traffic to the application server and provide a single location for these files (makes things easy when clustering) .. but if you don't have a lot of traffic and use a very simple setup, the nginx way is more than fine.

The issue around static files was discussed here : https://github.com/containous/traefik/issues/4240

3
  • I wonder however why S3 is called a "container". Word "container" is commonly associated with Docker containers and this may make confusion.
    – Gherman
    Jun 15, 2022 at 15:18
  • "Bucket" would probably fit better for s3
    – Grimmy
    Jun 15, 2022 at 20:50
  • I'm having a similar issue. I think I'm conceptually missing something. It sounds like I can place my static files i.e. directory produced from npm run build on a CDN? I'm using DigitalOcean Spaces CDN. Do I literally just upload that build folder to the CDN to serve the static files and just use Traefik for the API - no Nginx? If so, how does the initial request to my server know to route to the CDN for the static files?
    – Soubriquet
    Sep 11 at 13:29

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.