大家都知道php-fpm经常会占用很多cpu资源;所以想要尝试把nginx和php-fpm分开在两台服务器上搭建(本人并不确定这样是不是可以提高服务器性能,以后有时间会做测试);

    可能这种做法并不是主流的配置方案,所以网上资料比较少,而且都是编译安装,要修改很多很多参数,我看了几篇照着做也没有做出来j_0016.gif;本着不抛弃不放弃的精神,本人咨询了认识的几位大神,终于百般折腾把实验做通了(其实是让大神远程过来帮忙的j_0020.gif);

    声明,我这里所有的配置都是yum安装;所以步骤特别简单,想要深入的了解各参数的使用还是自己去找资料吧!!!


服务器如图:wKiom1WLqHvhVU56AABdovc9HcA026.jpg

Nginx服务器设置

[root@server06~]# yum install nginx #安装nginx

 [root@server06 ~]# cd /etc/nginx/conf.d/

[root@server06conf.d]# cp default.conf default.conf.bak

[root@server06conf.d]# vim default.conf

    location ~ \.php$ {
        root           /www;     #php-fpm服务器上*.php页面文件存放路径
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass   192.168.10.63:9000;  #这里指向处理php的服务器IP
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

[root@server06conf.d]# service nginx restart   #启动nginx服务


Php-fpm服务器设置

[root@server03~]# mkdir /www #创建php文件目录

[root@server03~]# vim /www/index.php #创建php主页,显示php信息

<?php
        phpinfo()
?>


[root@server03~]# yum install php-fpm  #安装php-fpm

[root@server03~]# vim /etc/php-fpm.d/www.conf     #配置文件修改

; The address onwhich to accept FastCGI requests.
; Valid syntaxesare:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specificaddress on
;                            a specific port;
;   'port'                 - to listen on a TCP socket toall addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unixsocket.
; Note: Thisvalue is mandatory.
;listen = 127.0.0.1:9000
listen = 192.168.10.63  #改成自己的IP地址
 
; List of ipv4addresses of FastCGI clients which are allowed to connect.
; Equivalent tothe FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI(5.2.2+). Makes sense only with a tcp listening socket. Each address
; must beseparated by a comma. If this value is left blank, connections will be
; accepted fromany ip address.
; Default Value:any
;listen.allowed_clients =127.0.0.1       
listen.allowed_clients = 192.168.10.66 #设置允许连接到 FastCGI 的服务器 IPV4 地址。如果允许所有那么把这条注释掉即可

[root@server03~]# service php-fpm start  #启动php-fpm


测试结果:

这里访问index.php已经可以显示php的信息了!!说明代理成功;

wKiom1WLqTKQU5j8AALfxNckIXY227.jpg

这里直接访问nginx服务器,则显示nginx的默认页面;说明是在server06这台服务器处理的;

wKioL1WLqu7hlnd1AAHVxNCrLf8942.jpg


另一篇博客有做尝试使用upstream代理后端多台php-fpm服务器;

贴上地址:http://dragondragon.blog.51cto.com/6170889/1665603