2019独角兽企业重金招聘Python工程师标准>>>
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服务器设置(server03和server04一样的配置)
[root@server03~]# mkdir /www #创建php文件目录
[root@server03~]# vim /www/index.php #创建php主页,显示php信息
1 2 3 4 |
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 var iable 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两台服务器;每次刷新都会轮询;
本文出自 “鬼迷心窍” 博客,请务必保留此出处http://dragondragon.blog.51cto.com/6170889/1665603