#nginx

45 posts

littleFedi: reverse proxy and split domains

littleFedi can use one domain for account handles and another for the server. For example:

  • @alice@example.com is the address people follow.
  • https://social.example.com serves the web interface, API, media and ActivityPub objects.

You can keep your existing website on example.com. It only needs a rule that redirects WebFinger requests to the littleFedi domain.

Choose both domains before creating accounts. Changing them later changes the instance’s identity.

littleFedi configuration

In littlefedi.toml, with the reverse proxy running on the same machine:

local_domain = "example.com"
web_domain = "social.example.com"

[http]
listen = "127.0.0.1:8080"
proxy_uri = "https://social.example.com"
trusted_proxies = ["127.0.0.1/32"]

If you already have an [http] section, edit it rather than adding another.

Point the DNS records for social.example.com at the reverse proxy. The server hosting example.com must also serve HTTPS. A DNS alias alone does not replace the WebFinger redirect.

Expose ports 80 and 443 on the proxy and keep port 8080 private. If the proxy runs on another machine, use a private listener address and trust only the proxy’s address.

Caddy

Add this to your Caddyfile, replacing the example domains:

social.example.com {
    reverse_proxy 127.0.0.1:8080
}

example.com {
    redir /.well-known/webfinger https://social.example.com{uri} 302
}

Caddy handles certificates and the WebSocket connections used for streaming.

If example.com already has a site block, add only the redir line to that block and keep the existing website configuration.

Check the configuration before reloading Caddy:

caddy validate --config /etc/caddy/Caddyfile

nginx

This configuration belongs in nginx’s http context, usually through an included site file. Replace the domains and certificate paths with your own.

Install valid certificates and arrange automatic renewal before enabling the HTTPS servers.

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    listen 80;
    listen [::]:80;
    server_name example.com social.example.com;
    return 308 https://$host$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name social.example.com;

    ssl_certificate /etc/letsencrypt/live/social.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/social.example.com/privkey.pem;
    client_max_body_size 41m;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_read_timeout 1h;
        proxy_buffering off;
    }
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location = /.well-known/webfinger {
        return 302 https://social.example.com$request_uri;
    }

    location / {
        return 404;
    }
}

If example.com already hosts a website, add only the WebFinger location to its existing HTTPS server block. Keep the website’s other rules instead of the return 404 shown above. If you already have the same map directive, do not add it twice.

Check the configuration before reloading nginx:

nginx -t

Check discovery

Use an existing local account, replacing alice with its username:

curl --fail -i 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com'

The response should redirect to social.example.com, keeping the resource query parameter.

Then follow the redirect:

curl --fail -L 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com'

The JSON should contain acct:alice@example.com as its subject, with an ActivityPub actor link at https://social.example.com/users/alice.

Finally, check a follow in both directions with another instance.

If account handles and the server use the same domain, only the reverse proxy is needed.

#littleFedi #SelfHosting #ReverseProxy #nginx #caddy

Load older posts