提高Web性能!Nginx与php-fpm部署不同服务器
FastCGI是一个可伸缩地,高速地在HTTP server和动态脚本语言间通信的接口。php-fpm是一个第三方的FastCGI进程管理器,FastCGI的主要优点是把动态语言和HTTP server 分离开来,所以Nginx与PHP-FPM经常被部署在不同的服务器上,已分挡前端Nginx服务器的压力。
环境:一台部署Nginx(Redhat6.4),一台单独部署php-fpm(Centos7)
地址:如下图
1.Nginx服务器的配置
安装nginx这里不做多的步骤可以看我另一篇随笔:https://www.cnblogs.com/daoguanmao/p/nginx_compiling.html
编辑主机配置文件(虚拟主机)
[root@redhat6 ~]# vim /opt/nginx/conf.d/domain1.conf server { listen 193.168.0.20:80; server_name www.domain1.com; access_log logs/domain1.access.log main; location / { index index.html index.php; root /data/web/; } location ~ \.php$ { root /web/; #这里是部署php-fpm 放置动态网页地址 fastcgi_pass 193.168.0.30:9000; #php-fpm地址 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } [root@redhat6 ~]# vim /data/web/index.html welcome to my nginx.domain1.com [root@redhat6 ~]# /opt/nginx/sbin/nginx -s reload #重启nginx
2.php-fpm服务器配置(需要源码编译的看我另一篇随笔https://www.cnblogs.com/daoguanmao/p/php-fpm.html)
[root@localhost ~]# yum install -y php-fpm [root@localhost ~]# vim /etc/php-fpm.d/www.conf ; Note: This value is mandatory. listen = 193.168.0.30:9000 #改成本机地址 ; Set listen(2) backlog. A value of '-1' means unlimited. ; Default Value: -1 ;listen.backlog = -1 ; List of ipv4 addresses of FastCGI clients which are allowed to connect. ; Equivalent to the 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 be separated by a comma. If this value is left blank, connections will be ; accepted from any ip address. ; Default Value: any listen.allowed_clients = 193.168.0.20 #Nginx地址 [root@localhost ~]# mkdir /web/ [root@localhost ~]# vim /web/index.php This is php-fpm Server <?php phpinfo(); ?> [root@localhost ~]# systemctl start php-fpm [root@localhost ~]# systemctl enable php-fpm
3.重启php-fpm后我们来验证访问
静态页面:
动态页面:
我的头怎么跟机关枪似的,
突突突~突突突的