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

Mathias Gilson
  • 483
  • 1
  • 5
  • 11

2 Answers2

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.

gdoubleod
  • 1,268
  • 3
  • 19
  • 33
ldez
  • 3,030
  • 19
  • 22
  • 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 ? – Taras Vaskiv Oct 31 '18 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 '19 at 08: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

Grimmy
  • 3,992
  • 22
  • 25