I have an nginx with two different php-fpm versions (7.4 and 8.1).
I want nginx to load these two php versions randomly.
For example, the info.php
loaded at this time is version 7.4, and version 8.1 should be displayed next time.
Is this possible?
Today, someone asked me a similar question, I searched here and found the question here, but no one answered it. I hope this answer helps others in the future too!
The answer to this question is, yes, it is possible. First, you need to define two separate upstream blocks for each PHP version, then use the
random
directive in the upstream block to enable random load balancing between the available PHP versions, and finally, in yourserver
block, you can use theproxy_pass
directive and the corresponding upstream block to proxy the request to the PHP version!like this:
As you can see, requests to the root URL (
/
) will be randomly routed to PHP version 7.4 or 8.1 using theproxy_pass
directive andphp7
upstream.