-
-
Notifications
You must be signed in to change notification settings - Fork 0
Enable traefik response compression #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
5af777e
6cb314d
c47c3aa
56014ee
c806bcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -193,6 +193,10 @@ TRAEFIK_ACCESS_LOG_ENABLED=true | |||||||||
| - ✅ Built-in Docker tooling for log access | ||||||||||
| - ✅ Optional detailed request tracing for debugging | ||||||||||
|
|
||||||||||
| ## Response Compression | ||||||||||
|
|
||||||||||
| Traefik automatically compresses HTTP responses using gzip and Brotli encoding for all proxied services. This is enabled by default and requires no additional configuration. Clients that send an `Accept-Encoding` header will receive compressed responses, reducing bandwidth usage and improving load times. | ||||||||||
|
||||||||||
| Traefik automatically compresses HTTP responses using gzip and Brotli encoding for all proxied services. This is enabled by default and requires no additional configuration. Clients that send an `Accept-Encoding` header will receive compressed responses, reducing bandwidth usage and improving load times. | |
| Traefik automatically compresses HTTP responses using gzip encoding for all proxied services. This is enabled by default and requires no additional configuration. Clients that send an `Accept-Encoding` header will receive compressed responses, reducing bandwidth usage and improving load times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrasing here could be slightly misleading. Stating "This is enabled by default" might imply it was a pre-existing feature of the project, whereas this pull request is introducing it. The proposed suggestion aims to clarify that this feature is now enabled by default within the proxy.
| Traefik automatically compresses HTTP responses using gzip and Brotli encoding for all proxied services. This is enabled by default and requires no additional configuration. Clients that send an `Accept-Encoding` header will receive compressed responses, reducing bandwidth usage and improving load times. | |
| This proxy enables response compression for all proxied services. Traefik automatically compresses HTTP responses using gzip and Brotli, depending on the client's `Accept-Encoding` header. This reduces bandwidth usage and improves load times without requiring any additional configuration for your services. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5341,6 +5341,120 @@ networks: | |||||||||||||
| - Traefik Headers Middleware: https://doc.traefik.io/traefik/middlewares/http/headers/ | ||||||||||||||
| - OWASP Secure Headers Project: https://owasp.org/www-project-secure-headers/ | ||||||||||||||
|
|
||||||||||||||
| #### Compression Middleware | ||||||||||||||
|
|
||||||||||||||
| The proxy includes a **compression middleware** (`compress`) that automatically compresses HTTP responses using gzip | ||||||||||||||
| encoding. This reduces bandwidth usage and improves page load times, especially for text-based content like HTML, CSS, | ||||||||||||||
| JavaScript, and JSON. | ||||||||||||||
|
Comment on lines
+5346
to
+5348
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This documentation only mentions
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| **How It Works:** | ||||||||||||||
|
|
||||||||||||||
| When a client sends a request with the `Accept-Encoding: gzip` header, Traefik compresses the response body before | ||||||||||||||
| sending it back. This is transparent to the application — no code changes are required. | ||||||||||||||
|
Comment on lines
+5352
to
+5353
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This explanation only refers to the
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| **Applying to Your Services:** | ||||||||||||||
|
|
||||||||||||||
| To enable compression for your custom services, add the middleware to your router labels: | ||||||||||||||
|
|
||||||||||||||
| ```yaml | ||||||||||||||
| services: | ||||||||||||||
| app: | ||||||||||||||
| image: your-app:latest | ||||||||||||||
| networks: | ||||||||||||||
| - traefik-proxy | ||||||||||||||
| labels: | ||||||||||||||
| - "traefik.enable=true" | ||||||||||||||
| - "traefik.http.routers.app.rule=Host(`app.docker.localhost`)" | ||||||||||||||
| - "traefik.http.routers.app.tls=true" | ||||||||||||||
| # Apply compression middleware | ||||||||||||||
| - "traefik.http.routers.app.middlewares=compress@file" | ||||||||||||||
|
|
||||||||||||||
| networks: | ||||||||||||||
| traefik-proxy: | ||||||||||||||
| external: true | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **Key Points:** | ||||||||||||||
|
|
||||||||||||||
| - The `@file` suffix tells Traefik to use middleware defined in the dynamic configuration file (`config/dynamic.yml`) | ||||||||||||||
| - Compression is applied automatically to the Traefik dashboard | ||||||||||||||
| - Only responses with compressible content types (e.g., `text/html`, `application/json`, `text/css`, `application/javascript`) are compressed | ||||||||||||||
| - Already-compressed content (e.g., images, videos) is not double-compressed | ||||||||||||||
| - You can chain multiple middlewares by separating them with commas: | ||||||||||||||
| `middlewares=compress@file,security-headers@file` | ||||||||||||||
|
|
||||||||||||||
| **Verification:** | ||||||||||||||
|
|
||||||||||||||
| After starting your service, verify that compression is active: | ||||||||||||||
|
|
||||||||||||||
| ```bash | ||||||||||||||
| curl -H "Accept-Encoding: gzip" -I https://app.docker.localhost 2>/dev/null | grep -i content-encoding | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **Expected output:** | ||||||||||||||
|
|
||||||||||||||
| ``` | ||||||||||||||
| Content-Encoding: gzip | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| To see the size difference, compare compressed vs uncompressed responses: | ||||||||||||||
|
|
||||||||||||||
| ```bash | ||||||||||||||
| # Compressed response size | ||||||||||||||
| curl -H "Accept-Encoding: gzip" -so /dev/null -w '%{size_download}' https://app.docker.localhost | ||||||||||||||
|
|
||||||||||||||
| # Uncompressed response size | ||||||||||||||
| curl -so /dev/null -w '%{size_download}' https://app.docker.localhost | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **Customizing Compression:** | ||||||||||||||
|
|
||||||||||||||
| If you need to exclude specific content types from compression (e.g., for already-compressed binary formats), you can | ||||||||||||||
| define a custom compress middleware in your project's compose file: | ||||||||||||||
|
|
||||||||||||||
| ```yaml | ||||||||||||||
| services: | ||||||||||||||
| app: | ||||||||||||||
| image: your-app:latest | ||||||||||||||
| networks: | ||||||||||||||
| - traefik-proxy | ||||||||||||||
| labels: | ||||||||||||||
| - "traefik.enable=true" | ||||||||||||||
| - "traefik.http.routers.app.rule=Host(`app.docker.localhost`)" | ||||||||||||||
| - "traefik.http.routers.app.tls=true" | ||||||||||||||
| # Define custom compress middleware with excluded content types | ||||||||||||||
| - "traefik.http.middlewares.custom-compress.compress.excludedContentTypes=image/png,image/jpeg,image/gif" | ||||||||||||||
| # Apply custom middleware | ||||||||||||||
| - "traefik.http.routers.app.middlewares=custom-compress" | ||||||||||||||
|
|
||||||||||||||
| networks: | ||||||||||||||
| traefik-proxy: | ||||||||||||||
| external: true | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **Common Use Cases:** | ||||||||||||||
|
|
||||||||||||||
| 1. **Combine compression with security headers:** | ||||||||||||||
| ```yaml | ||||||||||||||
| - "traefik.http.routers.app.middlewares=compress@file,security-headers@file" | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| 2. **Exclude specific content types from compression:** | ||||||||||||||
| ```yaml | ||||||||||||||
| - "traefik.http.middlewares.app-compress.compress.excludedContentTypes=application/pdf,image/svg+xml" | ||||||||||||||
| - "traefik.http.routers.app.middlewares=app-compress" | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| 3. **Set minimum response size for compression:** | ||||||||||||||
| ```yaml | ||||||||||||||
| - "traefik.http.middlewares.app-compress.compress.minResponseBodyBytes=1024" | ||||||||||||||
| - "traefik.http.routers.app.middlewares=app-compress" | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| **For More Information:** | ||||||||||||||
|
|
||||||||||||||
| - Traefik Compress Middleware: https://doc.traefik.io/traefik/middlewares/http/compress/ | ||||||||||||||
|
|
||||||||||||||
| ## Troubleshooting | ||||||||||||||
|
|
||||||||||||||
| This section covers common integration issues and their solutions. For each problem, we provide diagnostic steps and | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.