I have nginx deployed in front of Stalwart, with proxy_protocol on;, and everything is working fine. Thanks to PROXY protocol, I’m able to see original client IP addresses in DEBUG logs.
However, with such setup, nginx has no control or insight on HTTP requests, since it is now operating at the TCP layer. Therefore, I cannot enable gzip compression in nginx.
How can I enable gzip compression for static files served by Stalwart (e.g. the bundled WebUI)?
Stalwart doesn’t compress the files of the web applications it serves, the WebUI included: they go out exactly as they are in the bundle. Only a few built-in pages, like the login page and its assets, ship pre-compressed. The bundle’s other files are sent with an immutable cache header, though, so a browser downloads them once per WebUI release. If you’d like on-the-fly compression added, please post it in Feature Ideas.
You can get gzip from nginx by handling HTTPS at the HTTP layer and keeping the stream block with proxy_protocol on; for the mail ports. The http block then terminates TLS for 443 (so nginx needs the certificate for that hostname), enables gzip and proxies to a plain HTTP listener on Stalwart. The client address reaches Stalwart in X-Forwarded-For once you set clientIpSource to xForwardedFor in the HTTP settings. That setting covers every HTTP listener, so all of them must be reachable only through nginx, or a client could fake its address. Forwarding headers and Client IP address describe both parts.
The xForwardedFor approach is what I went with at first, and it worked pretty well, except that most DEBUG logs showed the IP address of the proxy in the remoteIp field, as discussed here.
And that very specific issue made me switch to the PROXY protocol approach.
Anyway, I just wanted to make sure that I’m not missing any configuration option, and your answer cleared that up.