by system2 · 2w ago · 0 comments
Nginx uses way less memory in most use-cases (1/4 to 1/10), but with dynamic content like php it is only slightly better (maybe 15% if lucky). Also, setting up websocket proxy in Nginx is still a bit of a bodge.
Each server type has its own trade offs, and a list of known mitigations the uninitiated must learn. If you have a single domain high-traffic site with static media files, than Nginx is probably going to matter more. =3
- php-fpm is easy, you can make the pool run as the domain's user/group directly
- nginx: you must add nginx's user (www-data) to the domain personal's group
The downside to this approach is that it's harder to reason about for someone unfamiliar with it and it's easy to misconfigure file permissions. There is also a limited number of extra groups a user can be part of before it becomes an issue (plus one fpm pool per user takes memory).
That being said the best massively-shared hosting system I've ever used was apache mpm_prefork with mod_php and mod_ruid2. It used as much(little) memory as a single user setup, it scaled to 10k users if you wanted, and file permissions were all naturally handled.
The way mod_ruid2 worked was to use linux capabilities to change the effective user/group of the apache process before serving the request, so it would run as the tenant's group and user, then switch back to nobody/nobody. It had very little overhead compared to things like mod_suphp and, more importantly, it also worked on static files and .htaccess!
The module has been abandoned and was never that popular so I always wondered if it was found to be exploitable or something... Thanks to Linux Capabilities an exploiter couldn't gain root, but as seen from the recent exploit apache's mod_php doesn't do a full cleanup so maybe there was leakage when the process was reused (but then that is solvable by limiting the requested to 1)