Skip to main content
nginx is a high-performance HTTP server and reverse proxy. This guide shows how to deploy Anubis behind nginx.

Deployment Architecture

Two common patterns:

Pattern 1: Reverse Proxy Mode

nginx forwards all traffic to Anubis, which validates and forwards to the backend:

Pattern 2: External Auth Mode

nginx uses Anubis as an authentication service:

Reverse Proxy Configuration

Upstream Definition

Define Anubis as an upstream in /etc/nginx/conf.d/upstream-anubis.conf:

Server Configuration

Create a reusable include file /etc/nginx/conf-anubis.inc:
Then include it in your server block:

Complete Example

Here’s a complete working configuration: docker-compose.yml

External Auth Configuration

For nginx’s auth_request module, configure Anubis without a target: Anubis configuration:
nginx configuration:

Unix Socket Configuration

For maximum performance when nginx and Anubis are on the same server: Anubis:
nginx upstream:
Ensure nginx has permission to access the socket (nginx user must be in the anubis group).

Multi-Site Configuration

You can protect multiple sites with one Anubis instance:
Configure Anubis with cookie domain:
This allows the Anubis cookie to work across all *.example.com subdomains.

TLS Considerations

When nginx terminates TLS and forwards HTTP to Anubis, some applications (like WordPress) may not detect HTTPS correctly. Configure your application to trust the X-Forwarded-Proto header. For WordPress, add to wp-config.php:

Testing

Verify headers are being forwarded correctly:
Check nginx logs to ensure traffic flows correctly:

Performance Tuning

Connection Keepalive

Buffering

Troubleshooting

Anubis sees nginx’s IP instead of client IP

Make sure you’re not using --use-remote-address when behind nginx. Anubis should read from X-Real-IP or X-Forwarded-For headers.

502 Bad Gateway

Check that:
  1. Anubis is running and listening on the correct address
  2. nginx can reach Anubis (check network connectivity)
  3. If using Unix socket, verify permissions

Redirect loops

Ensure:
  1. REDIRECT_DOMAINS includes your domain
  2. Cookie domain is set correctly
  3. HTTPS is properly detected (check X-Forwarded-Proto)