Check for existence of PHP socket availability with `nginx -t`
Maxim Dounin
mdounin at mdounin.ru
Mon Mar 15 05:02:35 UTC 2021
Hello!
On Sun, Mar 14, 2021 at 11:33:02AM -0400, petecooper wrote:
> I have some servers running PHP applications on Nginx via PHP-FPM. Each
> server uses a named socket in the filesystem. Nginx can often pass its
> configuration test but the server does not function as expected if the named
> socket file is not there (i.e. PHP-FPM is not running as expected).
>
> Is it possible to integrate a check for the existence of that socket file in
> the `nginx -t` process? I am able to create a shell script to check for the
> socket and then run `nginx -t`, but I am wondering if there is a native
> route to check.
Short answer is: no.
Long answer:
nginx does not care if the upstream socket is reacheable or not
when it parses configuration, it is only important when processing
a particular request. That is, nginx can (and will) start just
fine if the socket doesn't exist (or, similarly, upstream server's
IP address isn't reachable). And that's what "nginx -t"
checks for: if nginx itself will be able to start.
As long as your upstream server is reachable when a request comes
in, the request will be passed to it. If the backend server is
not reacheable for some reason - an error will be returned to the
client (and you can configure custom processing for the error
using the error_page directive - for example, you can configure
nginx to try a different upstream server instead). In particular,
this makes it possible to restart nginx and your backend servers
independently.
If your use case is simple enough and you want both nginx and
corresponding PHP-FPM processes to be running at the same time,
and, for example, don't want to start nginx if PHP-FPM isn't
running - this is something to check by means external to nginx.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx
mailing list