最近又重新看了一遍   'nginx入门到精通'      抽点时间 出来搭几个Demo  会有更深体会:

Nginx如何与Php-fpm结合

Nginx不只有处理http请求的功能,还能做反向代理。Nginx通过反向代理功能将动态请求转向后端Php-fpm。

nginx与php-fpm的结合,完整的流程是这样的

环境说明:
    OS:centos6.8 x86  

主机IP:

191,168.1.26   nginx

191,168.1.27   php-fpm

191,168.1.28   mysql

1  Nginx 安装

 

yum install gcc* wget  -y     #都懂得

安装nginx 相关依赖:  *-devel  (开发包)

# pcre 支持正则表达式
# zlib 支持数据压缩
# openssl支持HTTPS
 yum install zlib zlib-devel pcre pcre-devel openssl openssl-devel -y  

下载Nginx 源码包:
#cd /usr/src
#下载:nginx-1.8.1.tar.gz 解压 tar -zxvf nginx-1.8.1.tar.gz
cd /usr/src && wget http://mirrors.sohu.com/nginx/nginx-1.8.1.tar.gz && tar -zxvf nginx-1.8.1.tar.gz 

cd ./nginx-1.8.1

创建groupadd useradd用户 : www   # 创建nginx worker进程工作用户
groupadd -g 700 www
useradd -u 800 -g 700 -s /sbin/nologin www   
安装nginx 
#--with-http_ssl_module 启用HTTPS加密
#--with-http_stub_status_module 启用nginx状态监控
#--with-http_gzip_static_module 启用静态压缩
#--with-http_realip_module 做代理时获取客户端真实IP ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
--with-http_gzip_static_module --with-http_realip_module --with-pcre --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module 
[root@26_Nginx nginx-1.8.1]#  make && make install

[root@26_Nginx nginx-1.8.1]#   vim /etc/init.d/nginx # 创建nginx服务脚本
 
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
} restart() {
configtest || return $?
stop
sleep 1
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
$nginx -t -c $NGINX_CONF_FILE
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null 2>&1
} case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac

授权file   

[root@26_Nginx nginx-1.8.1]# chmod +x /etc/init.d/nginx 

Nginx   添加 用户  组

[root@26_Nginx nginx-1.8.1]# vim /usr/local/nginx/conf/nginx.conf

       user www www;

    service nginx start

    添加开机启动项    chkconfig nginx on

临时关闭  防火墙: iptables -F

修改   nginx 配置文件如下:

vim /usr/local/nginx/conf/nginx.conf

配置修正:

location ~ \.php$ {
root /www;
fastcgi_pass 191.168.1.27:9000;
fastcgi_index index.php;
include fastcgi.conf;
}

配置文件检查:

/usr/local/nginx/sbin/nginx  -t

[root@26_Nginx nginx-1.8.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

1.2  nfs + rpcbin  安装  共享文件存储server

创建网站测试文件:

mkdir /www

创建测试文件:

echo '<?php  phpinfo(); ?>' >> /www/index.php

yum install nfs-utils rpcbin -y

修改nfs 配置文件件

echo '/www 191.168.1.0/24' >>  /etc/exports

重启 nfs rpcbin 服务:

service rpcbind  restart

service nfs  restart

两台主机可重启一下   ntpd   对一下时间     yum install ntpd -y     

service  ntpd  restart

2:php—191.168.1.27:

    nfs 安装:

    yum install nfs-utils rpcbind -y

    挂载  nginx 主机 nfs 到 /www

     mount -t nfs 191.168.1.26:/www /www

安装 php-fpm 依赖:

yum install libmcrypt libmcrypt-devel mhash mhash-devel  libxml2-devel openssl openssl-devel bzip2-devel libcurl-devel gd -y

 EPEL源 没有 libmcrypt , mhash 包  

更换EPEL源 :

 [root@php_27 ~]# vim /etc/yum.repos.d/epel-centos6.repo
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 [epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0 [epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=0

  yum repolist

重新安装  

yum install libmcrypt libmcrypt-devel mhash mhash-devel  libxml2-devel openssl openssl-devel bzip2-devel libcurl-devel



创建PHP  运行 组·用户
groupadd -g 700 www
useradd -u 700 -g 700 -s /sbin/nologin www php --with 一些参数说明:
---------------------------------------------------------------
 1 ./configure --prefix=/usr/local/php \      //安装位置
2 --with-mysql \                   //支持mysql
3 --with-pdo-mysql \                //支持pdo模块
4 --with-mysqli \                  //支持mysqli模块         
5 --with-openssl \                  //支持openssl模块
6 --enable-fpm \                   //支持fpm模式
7 --enable-sockets \                //启用socket支持
8 --enable-sysvshm \                //启用系统共享内存支持
9 --enable-mbstring \                //使多字节字符串的支持
10 --with-freetype-dir \              //设置FreeType安装前缀路径
11 --with-jpeg-dir \                //设置libjpeg安装前缀路径
12 --with-png-dir \                //设置libpng安装前缀路径
13 --with-zlib-dir \                //设置libz安装前缀路径
14 --with-libxml-dir=/usr \            //设置libxml2安装路径
15 --enable-xml \                 
16 --with-mhash \                 //支持mhash
17 --with-mcrypt \                 //支持mcrypt
18 --with-config-file-path=/etc \        //配置文件路径
19 --with-config-file-scan-dir=/etc/php.d \ //配置文件扫描路径
20 --with-bz2 \               //支持BZip2
21 --with-curl                   //支持curl

---------------------------------------------------------------
 
下载PHP 源码包并解压:
cd /usr/src/ && wget http://mirrors.sohu.com/php/php-5.6.7.tar.gz && tar -zxvf php-5.6.7.tar.gz
cd php-5.6.7

./configure --prefix=/usr/local/php --enable-fpm --enable-ftp --enable-zip --enable-xml --enable-sockets --enable-bcmath --enable-pcntl --enable-shmop --enable-soap --enable-sysvsem --enable-mbstring --enable-mbregex --enable-inline-optimization --enable-maintainer-zts --enable-gd-native-ttf
--with-fpm-user=www --with-fpm-group=www --with-mysql --with-mysqli --with-pdo-mysql --with-openssl --with-freetype-dir --with-iconv-dir --with-jpeg-dir --with-png-dir --with-libxml-dir --with-curl --with-zlib --with-bz2 --with-xmlrpc --with-gd --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d

编译时间有点长:

COPY  启动脚本到 /etc/init.d/

[root@php_27 php-5.6.7]# cp -a sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php_27 php-5.6.7]# chmod +x /etc/init.d/php-fpm
[root@php_27 php-5.6.7]# cp -a php.ini-production /usr/local/php/etc/php.ini
[root@php_27 php-5.6.7]# cd /usr/local/php/etc/
[root@php_27 etc]# cp -a php-fpm.conf.default php-fpm.conf

[root@php_27 etc]# vim php-fpm.conf  # 修改监听地址

listen = 191.168.1.27:9000

重启  nginx

3  安装MYSQL   #第三台主机  191.168.1.28  安装Mysql

先来安装NFS  rpcbind 并且挂载到 nginx  php-fpm

yum install nfs-utils   rpcbind -y

测试用先关闭 iptables -F

创建/WWW  网站目录         #这里可以使用git管理网站目录

mkdir /www

修改NFS配置文件

echo "/www    191.168.1.1/24(rw,no_root_squash)" >> /etc/exports

重启服务

service rpcbind  start

service nfs start

在其它两台主机

showmount -e 191.168.1.28  #error

clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

或    clnt_create: RPC: Unknown host的解决方法

第一条为  我 用了 iptables -F  解决   iptables stop

第二条    echo '191.168.1.28 mysql_server' > /etc/hosts

在次  showmount -e   mysql_server

在次挂载  OK

mount -t nfs mysql_server:/www   /www

mount -l

yum install mysql mysql-server mysql-devel -y

												

Nginx php-fpm 分离搭建 (上) 未完的更多相关文章

  1. virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续)

    virtualbox搭建ubuntu server nginx+mysql+tomcat web服务器1 (未完待续) 第一次接触到 linux,不知道linux的确很强大,然后用virtualbox ...

  2. nginx与php分离搭建

    nginx与php分离搭建 nginx配置 server { listen       80;      定义端口 server_name  www.a.org;    定义域名 location / ...

  3. Kubernetes(二)-- 搭建(未完待续)

    一.部署前规划 1. 操作系统初始化设置 :需要设置好集群机器,关闭防火墙和selinux 2. 创建ca证书和私钥 :集群间通信要加密,那么肯定要有ca的创建,以后就用这一步创建的ca当作证书颁发机 ...

  4. MacOS下Rails+Nginx+SSL环境的搭建(上)

    这里把主要的步骤写下来,反正我是走了不少弯路,希望由此需求的朋友们别再走类似的弯路.虽说环境是在MacOS下搭建,但是基本上和linux下的很相像,大家可以举一反三. 一.安装Rails 这个是最简单 ...

  5. Java Web 1-开发环境搭建(未完待续)

    Java Web包含什么?前台.后台,前台的HTML.JSP,后台的Servlet.(目前所知) 开发环境: JDK,MySQL,Tomcat,Eclipse @ Windows 10 说明:本文总结 ...

  6. 快速安装Nginx及配置详解(未完待续)

    导读: Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器,从2007年被德国人开发出来后可以说在市场的占有率一路飙升,因为它支持高并 ...

  7. 搭建EOS未完

    纯净机器上部署 EOS 测试网 演示的系统为 Ubuntu 18.04 LTS,内存8g以上,硬盘300g+ clone EOS代码 们以EOS-Mainnet仓库部署,(EOS-Mainnet是部署 ...

  8. [ambari环境搭建](未完待续)

    [安装] https://blog.csdn.net/Happy_Sunshine_Boy/article/details/86595945#commentBox https://www.jiansh ...

  9. nginx服务器的负载均衡和动静分离(未完)

    安装nginx,我的博客里面有介绍源码和yum安装. 实战:使用nginx实现动静分离的负载均衡集群 实战:使用haproxy实现负载均衡集群 LB负载均衡集群分为两类:LVS(四层)和Nginx或p ...

随机推荐

  1. Visual Studio C++覆盖率测试异常的解决方法

    默认的UnitTest可能出现这样的异常 经过查阅资料最终找到了解决办法 步骤如下: 在测试项目右键属性 将配置属性->链接器->调试 生成调试信息修改为如图所示,然后再进行覆盖率测试 就 ...

  2. java程序中的经常出现的的异常处理课后总结

    一.JDK中常见的异常情况 1.常见异常总结图 2.java中异常分类 Throwable类有两个直接子类: (1)Exception:出现的问题是可以被捕获的 (2)Error:系统错误,通常由JV ...

  3. 怎样实现android 返回到上一个Activity并重新执行一次onCreate方法

    1.onCreate 方法只在activity一开始创建的时候执行.2.也就是在该activity销毁后才能再次执行,假如当前activity上再打开一个activity,并且原来的activity已 ...

  4. bootloader 详细介绍

    Bootloader 对于计算机系统来说,从开机上电到操作系统启动需要一个引导过程.嵌入式Linux系统同样离不开引导程序,这个引导程序就叫作Bootloader. 6.1.1  Bootloader ...

  5. Codeforces 1296E2. String Coloring (hard version)

    这道题和HDU1257一模一样,一开始窝都用贪心直接解,没法理解为什么求一个最长下降序列,直到看了巨巨的题解,先给出一个定理,Dilworth's theorem,离散学不好,补题两行泪,该定理是说, ...

  6. Socket传输大文件(发送与接收)

    下载 Client using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

  7. centos查找文件\目录\内容命令

    1.查找文件 find / -name 'php.ini'12.查找目录 find / -name 'path' find / -name 'path' -type d13.查找内容 find . | ...

  8. C++ Primer Plus 6 笔记(2)

    第4章 1.求数组元素个数的一种方法:num=sizeof 数组名/sizeof (元素类型) 2.确定字符串所需的最短数组时,别忘了将结尾的'\0'计算在内.表面可以无,内存必须有. 3.'S'表示 ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:响应式图片

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Matplotlib 基本概念

    章节 Matplotlib 安装 Matplotlib 入门 Matplotlib 基本概念 Matplotlib 图形绘制 Matplotlib 多个图形 Matplotlib 其他类型图形 Mat ...