准备环境:

192.168.1.104       nginx服务器

192.168.1.105       PHP

192.168.1.106       PHP

安装nginx(yum安装)

yum install epel-release -y

yum install nginx -y 

启动nginx

systemctl start nginx

查看nginx进程

在nginx服务器上配置nginx虚拟主机

cd /etc/nginx/conf.d

vim lnp.conf

server {
        listen       8000;
        server_name  localhost;
        location / {
        root /data/html;
        }

     location ~* .*\.php$ {
            root           /data/html;
            fastcgi_pass   php_web;
            fastcgi_index  index.php;            
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}
 upstream php_web {
    server 192.168.1.105:9000;
    server 192.168.1.106:9000;
    }
nginx -t 测试配置文件是否有错

在/data/html目录下新建index.php文件

<?php
phpinfo();
?>
重启nginx

systemctl start nginx

在后端机器上(192.168.1.105,192.168.1.106)安装php,并启动

yum install php-fpm -y

编辑php配置文件(192.168.1.105和192.168.1.106都要更改配置文件)

vim /etc/php-fpm.d/www.conf

在192.168.1.105和192.168.1.106的/data/html目录下新建一个index.php文件

<?php
phpinfo();
?>

重启php(192.168.1.105和192.168.1.106都要重启)

systemctl start php-fpm

访问nginx服务器,页面如下:

更多推荐