Just a quick note.
Nginx will include configuration files based on ASCII ordering. This means that even if you have two files default (with the default config) and cloud, cloud will be included before default and will answer for any undefined hostnames.
The easy way to solve this (and obvious if you have been around Linux for a while) is to prefix all config files with a number. For example:
This will result in 00-default being included in the configuration first.
I hope this is useful for someone out there.
Nginx wont auto-spawn workers if they don’t exist so you do need to start them outside of Nginx. Many people use the spawn-fastcgi script or some other startup script to do it, but the smart people use a process monitor.
There are a lot of people using supervisord for keeping their fastcgi PHP workers working and most of them are in my opinion doing it wrong. Not very wrong, just a few things that could be done better.
If you simply wanted PHP running as a certain user suphp and similar solutions are perfectly fine. FastCGI is slightly faster, but is more complex to manage – you need to keep it running. The way most people do it is something like the following:
Which spawns many separate PHP threads and it works. The problem with it is that if you use APC or similar opcode caches or in memory caches they are done on a per interpreter basis and as such if you spawn 20 PHP processes, you will have 20 separate opcode caches each with similar information.
A better way is to use the ability of the FastCGI PHP binary to manage its own children:
command=/usr/bin/php-cgi -b 127.0.0.1:9000
If you use APC or similar op-code caches this is much more efficient as only one cache is kept and has the side effect of much faster restarts within supervisord.