nginx后端代理多台php-fpm服务器;(补充上一篇博客)

wKioL1WLs4ihtyTBAACes8o-JyE319.jpg

Nginx服务器设置

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

[root@server06 ~]# cd/etc/nginx/

[root@server06 nginx]# vim nginx.conf

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

  

    log_format main  '$remote_addr - $remote_user[$time_local] "$request" '

                      '$status $body_bytes_sent"$http_referer" '

                     '"$http_user_agent" "$http_x_forwarded_for"';

  

    access_log /var/log/nginx/access.log  main;

  

    sendfile        on;

    #tcp_nopush     on;

  

    keepalive_timeout  65;

  

    #gzip on;

     

        upstream fastcgiserver { #设置后端php-fpm服务器ip及端口

        server 192.168.10.63:9000;   

        server 192.168.10.64:9000;

        }

         

    include /etc/nginx/conf.d/*.conf;

}

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

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

[root@server06 conf.d]# vimdefault.conf

1

2

3

4

5

6

7

8

    location ~ \.php$ {

        root           /www;     #php-fpm服务器上*.php页面文件存放路径

        #fastcgi_pass   127.0.0.1:9000;

        fastcgi_pass   fastcgiserver;  #这里调用upstream设置;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

    }

[root@server06 conf.d]# servicenginx restart   #启动nginx服务

 

Php-fpm服务器设置(server03server04一样的配置)

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

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

 

1

2

3

4

<?php

echo "server03";    #这里仅仅用来识别server03和server04

        phpinfo()

?>

 

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

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

; 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

 

测试结果:可以看到这里是分别调用了server03和server04两台服务器;每次刷新都会轮询;

 

wKiom1WLsmOTl4uAAAGbzSkzRkg922.jpg

wKioL1WLtB-AtsM0AAM4REoU8nE633.jpg


 

 

本文出自 “鬼迷心窍” 博客,请务必保留此出处http://dragondragon.blog.51cto.com/6170889/1665603

转载于:https://my.oschina.net/slagga/blog/910076

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值