Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to serve static resources with Traefik?

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

like image 248
Mathias Gilson Avatar asked Sep 30 '17 14:09

Mathias Gilson


People also ask

Does Traefik do load balancing?

Traefik is a leading modern reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components and configures itself automatically and dynamically.

Does Traefik use nginx?

Airbnb, Uber Technologies, and Spotify are some of the popular companies that use nginx, whereas Traefik is used by Docplanner, Viadeo, and Condé Nast.

What is Traefik service?

Traefik Mesh is a straight-forward, easy to configure, and non-invasive service mesh that allows visibility and management of the traffic flows inside any Kubernetes cluster. Get StartedJoin the Community.


2 Answers

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.

like image 183
ldez Avatar answered Sep 24 '22 14:09

ldez


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 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

like image 38
Grimmy Avatar answered Sep 21 '22 14:09

Grimmy