Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The statement claims Traefik compresses responses using "gzip and Brotli encoding," but the compress middleware configuration in config/dynamic.yml only enables gzip compression by default. Brotli compression requires additional configuration that is not present in this PR. Please update this to only mention gzip encoding, or add Brotli configuration if that capability is intended.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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.


## Testing

The project includes a comprehensive test suite for the `setup.sh` script to ensure reliability across different platforms and configurations.
Expand Down
3 changes: 3 additions & 0 deletions config/dynamic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ http:
X-XSS-Protection: "0"
Strict-Transport-Security: "max-age=31536000; includeSubDomains"
Content-Security-Policy: "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; object-src 'none'; base-uri 'self'"

compress:
compress: {}
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ services:
- "traefik.http.routers.dashboard.rule=Host(`traefik.docker.localhost`)"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.tls=true"
- "traefik.http.routers.dashboard.middlewares=security-headers@file"
- "traefik.http.routers.dashboard.middlewares=security-headers@file,compress@file"

redis:
image: redis:8.6.0-alpine
Expand Down Expand Up @@ -131,7 +131,7 @@ services:
- "traefik.enable=true"
- "traefik.http.routers.pma.rule=Host(`pma.docker.localhost`)"
- "traefik.http.routers.pma.tls=true"
- "traefik.http.routers.pma.middlewares=security-headers@file"
- "traefik.http.routers.pma.middlewares=security-headers@file,compress@file"

pgadmin:
image: dpage/pgadmin4:9.12.0
Expand Down Expand Up @@ -160,7 +160,7 @@ services:
- "traefik.enable=true"
- "traefik.http.routers.pgadmin.rule=Host(`pgadmin.docker.localhost`)"
- "traefik.http.routers.pgadmin.tls=true"
- "traefik.http.routers.pgadmin.middlewares=security-headers@file"
- "traefik.http.routers.pgadmin.middlewares=security-headers@file,compress@file"

mailpit:
image: axllent/mailpit:v1.29.1
Expand All @@ -183,7 +183,7 @@ services:
- "traefik.enable=true"
- "traefik.http.routers.mailpit.rule=Host(`mailpit.docker.localhost`)"
- "traefik.http.routers.mailpit.tls=true"
- "traefik.http.routers.mailpit.middlewares=security-headers@file"
- "traefik.http.routers.mailpit.middlewares=security-headers@file,compress@file"
- "traefik.http.services.mailpit.loadbalancer.server.port=8025"

volumes:
Expand Down
114 changes: 114 additions & 0 deletions docs/INTEGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This documentation only mentions gzip encoding. However, Traefik's compress middleware also supports Brotli (br), which offers better compression ratios and is preferred by modern browsers. For consistency with the main README.md and for accuracy, it would be beneficial to mention Brotli here as well.

Suggested change
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.
The proxy includes a **compression middleware** (`compress`) that automatically compresses HTTP responses using Gzip and Brotli
encoding. This reduces bandwidth usage and improves page load times, especially for text-based content like HTML, CSS,
JavaScript, and JSON.


**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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This explanation only refers to the Accept-Encoding: gzip header. To be more comprehensive, it's worth mentioning that clients can also negotiate for Brotli (br) compression, which is also supported and widely used.

Suggested change
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.
When a client sends a request with an `Accept-Encoding` header supporting `gzip` or `br` (Brotli), Traefik compresses the response body before
sending it back. This is transparent to the application — no code changes are required.


**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
Expand Down