问题
I have a three php-fpm servers, and a one nginx server, where I want to loadbalance php-fpm using nginx server.
php-fpm server1 - 192.168.10.31 php-fpm server2 - 192.168.10.32 php-fpm server3 - 192.168.10.33
nginx - server - 192.168.10.12
My Configuration on nginx server was;
upstream php_backend {
server 192.168.10.31:9000;
server 192.168.10.32:9000;
server 192.168.10.33:9000;
}
location ~ \.php$ {
fastcgi_pass php_backend;
}
But my problem is, where should I define the webroot [ root /path/to/webfiles ]
Because on nginx server [ 192.168.10.12 ], access log says file not found - 404. Where should I keep website php files? On nginx server or php servers? or in both nginx and php servers?
回答1:
This is kind of an old question, but I'll give my answer here for anyone googling this.
Robbie Averill's comment is correct. You should host your files both on Nginx and PHP servers. You can do this with an NFS share, but this might slow things down.
To work around this you could update your code on the nginx server and then rsync to the php servers. You could easily build a bash script that does something like:
rsync -avzp -e ssh /srv/www/ svc_internal@php.insypro.com:/srv/www/
rsync -avzp -e ssh /srv/www/ svc_internal@php2.insypro.com:/srv/www/
rsync -avzp -e ssh /srv/www/ svc_internal@php3.insypro.com:/srv/www/
Of course, you'd want to include this in one bash script that does the updating of your code, and synchronises the php machines.
来源:https://stackoverflow.com/questions/37402788/nginx-php-fpm-cluster