美文网首页
Nginx 安装 以及连接PHP

Nginx 安装 以及连接PHP

作者: fangfc | 来源:发表于2018-12-09 23:01 被阅读0次

    1. Nginx 是什么

    Nginx 是一个高性能Web 和反向代理服务器,具有非常多的优越的特性.

    • 作为Web服务器

      • 相比Apache, Nginx 占用更少的资源, 支持更多的并发性能, 体现了更加高的效率, 这使得Nginx 更加受到欢迎, 支持高达 50000 个并发连接响应. 因为Nginx 选择使用了 epoll 或 kqueue 作为开发模型.
    • 作为 负载均衡服务器:

      • Nginx 既可以在内部直接支持Rails 和 PHP, 也可以支持作为HTTP代理服务器 对外部进行服务, Nignx 用 C 比那些, 不论系统资源开销还是CPU使用效率都要比 perlbal好很多.
    • 作为邮件服务器

      • Nginx 同时是一款非常优秀的邮件服务器(最早开发该产品的目的之一 就是作为邮件服务器)

    Nginx 安装简单, 配制文件简洁(支持Perl 语法),可以做到 7*24 不断运行, 并且支持正常运行时的版本升级.

    2. 编译安装Nginx

    1. 准备源码包
    [root@node10009 src]# ls ./nginx-1.14.0.tar.gz 
    ./nginx-1.14.0.tar.gz
    [root@node10009 src]# tar zxf ./nginx-1.14.0.tar.gz 
    [root@node10009 src]# cd nginx-1.14.0
    [root@node10009 nginx-1.14.0]# ls
    auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
    [root@node10009 nginx-1.14.0]# 
    
    1. 安装准备
    # 安装gcc, gcc-c++, automake, autoconf, libtool make 
    yum -y install gcc gcc-c++ automake autoconf libtool make
    
    # nginx 的 rewrite需要有pcre 开发库的支持, 以及zip 的开发库的支持
    yum -y install pcre-devel zlib-devel
    
    # Nginx 想要使用HTTPS 的话, 需要openssl 的支持
    openssl-1.0.2o.tar.gz
    
    
    1. 编译准备
    ./configure \
        --prefix=/opt/app/nginx \
        --modules-path=/opt/app/nginx/modules \
        --with-file-aio \
        --with-threads \
        --with-http_addition_module \
         --with-http_auth_request_module \
         --with-http_flv_module \
         --with-http_gunzip_module \
         --with-http_gzip_static_module \
         --with-http_mp4_module  \
         --with-http_random_index_module \
         --with-http_realip_module \
         --with-http_secure_link_module \
         --with-http_slice_module \
         --with-http_ssl_module \
         --with-http_sub_module \
         --with-http_stub_status_module \
         --with-http_v2_module \
         --with-stream \
         --with-stream_ssl_module \
         --with-openssl=../openssl-1.0.2o \
         --with-openssl-opt='enable-ssl2' \
         --with-debug
    
    ----------------- 
    # 配置说明
    --prefix=PATH 
        配置安装目录
    --sbin-path=PATH
        # 配置可执行文件的路径
    --conf-path=PATH
        # 设置配置文件路径
    --error-log-path=PATH
        # 配置错误日志路径
    --user=NAME
    --group=NAME
        # 设置工作进程的进程名(Nginx 工作为主进程 启动工作进程)
    --with-file-aio
        # 启用AIO 机制,(异步IO)
    --with-threads 
        # 启用多线程
    --with-http_addition_module 
        # 使用 addition 模块, 允许在 响应前后添加文本,默认安装没有该模块
     --with-http_auth_request_module 
        # 使用auth_request 模块, 用于对请求做客户端授权, 默认没有
     --with-http_flv_module 
        # 提供flv (flash Video) 流媒体文件服务器的支持
     --with-http_gunzip_module
        # 允许使用 Content=Encoding: gzip, 来进行压缩
     --with-http_gzip_static_module
        # 允许使用 .gz 文件作为扩展名, 而不是常规文件.
     --with-http_mp4_module 
        # 支持 mp4 流媒体文件,
     --with-http_random_index_module
        # 支持使用 以'/'(斜杠) 作为结尾, 并且选择目录中随机文件作为索引文件, 
     --with-http_realip_module
        # 支持将客户端地址更改为指定 头字段中发送的地址
     --with-http_secure_link_module 
        # 用于检查连接的真伪, 保护资源免受未经授权的访问, 可用于将连接地址设置成md5指, 在访问时, 对比哈希中的 md5值
     --with-http_slice_module 
        # 该模块用于将请求分解为子请求, 每个模块都有一定范围的相应, 提供了有效的缓存
     --with-http_ssl_module 
        # 对 HTTPS 的支持
     --with-http_sub_module 
        # 将一个指定字符串替换成 响应请求
     --with-http_stub_status_module 
        # 提供基本状态信息的访问
     --with-http_v2_module 
        # 添加对 http/2 的支持
     --with-stream
        # 允许使用 负载均衡
     --with-stream_ssl_module 
        # 允许使用 支持SSL/TLS 的负载均很
     --with-openssl=../openssl-1.0.2o
        # 设置 openssl 的地址
     --with-openssl-opt='enable-ssl2'
        # 设置OpenSSL 的其他构建选项
     --with-debug
        # 使用 Debug
    

    3. 编译安装PHP

    1. 准备源码包
    [root@node10009 php-7.1.15]# ls ./php-7.1.15.tar.bz2 
    ./php-7.1.15.tar.bz2
    [root@node10009 php-7.1.15]# tar jxf ./php-7.1.15.tar.bz2
    [root@node10009 php-7.1.15]# cd ./php-7.1.15
    
    1. 编译安装
    ./configure \
        --prefix=/opt/app/php7 \
        --with-config-file-path=/opt/app/php7/etc \
        --disable-ipv6 \
        --enable-bcmath \
        --enable-dba \
        --enable-ftp \
        --enable-mbstring \
        --enable-sockets \
        --enable-exif \
        --enable-pcntl \
        --enable-soap \
        --enable-zip \
        --with-curl \
        --with-iconv \
        --with-gettext \
        --with-gd \
        --with-gmp \
        --with-freetype-dir \
        --with-jpeg-dir \
        --with-png-dir \
        --with-mcrypt \
        --with-mhash \
        --with-openssl \
        --with-tidy \
        --with-zlib \
        --with-mysqli=mysqlnd \
        --with-pdo-mysql=mysqlnd \
        --enable-fpm \
        --with-apxs2=/opt/app/apache24/bin/apxs
    
    ---------------
    # 选项说明
    --prefix=/opt/app/php7
        # 安装目录
    --with-config-file-path=/opt/app/php7/etc
        # 设置配置文件路径
    --disable-ipv6
        # 不使用ipv6
    --enable-sockets
        # 使用socket
    --enable-pcntl
        # 使用进程控制
    --enable-zip
        # 使用zip
    --with-curl
        # clear URL, 能偶遇连接各种服务, 可使用多种协议
    --with-gettext
        # 可用于国际化PHP程序
    --with-gd
        # 使用gd库
    --with-gmp
        # 声依永 GUN MP库, 处理任意长度的整数
    --with-freetype-dir
        # 打开对 freetype 字体库的支持
    --with-jpeg-dir
        # 对jpeg图片的支持
    --with-png-dir
        # 对png 图片的支持
    --with-mcrypt
        # 可以使用 mcrypt,
    --with-mhash
        #  mhash 算法
    --with-openssl
        # openssl的支持, 用作加密传输
    --with-tidy
        # 可用于编译文档树, 用于嵌入式脚本语言(如php, asp)
    --with-zlib
        # 打开zlib 库的支持
    --with-mysqli=mysqlnd
    --with-pdo-mysql=mysqlnd
        # mysqli 和 mysql pdo 的支持
    --enable-fpm
        # 开启fpm
    --with-apxs2=/opt/app/apache24/bin/apxs
        # 添加apache的支持
    
    1. 尝试启动
    [root@node10009 php7]# /opt/app/php7/sbin/php-fpm 
    [root@node10009 php7]# ss -tln
    State      Recv-Q Send-Q            Local Address:Port                           Peer Address:Port              
    LISTEN     0      128                           *:22                                        *:*                  
    LISTEN     0      128                   127.0.0.1:9000                                      *:*                  
    LISTEN     0      128                   127.0.0.1:3306                                      *:*                  
    LISTEN     0      128                          :::22                                       :::*                  
    [root@node10009 php7]# 
    

    4. 设置nginx 的php文件解析

    • 配置nginx 配置文件
    server {
        listen 81;
        server_name     localhost;
        root            /opt/case/wwwroot/host1;
        index           index.html index.php;
       charset         utf8;
       location ~ \.php$ {
           fastcgi_pass        127.0.0.1:9000;
           fastcgi_index       index.php;
           fastcgi_param       SCRIPT_FILENAME     /opt/case/wwwroot/host1/$fastcgi_script_name;
           include             fastcgi_params;
        }
    }
    --------------------
    # 说明
    fastcgi_pass:
        # 设置php程序的位置, 可以是网络地址+端口, 也可以是 本地的php socket连接
    fastcgi_index:
        # 指明首页文件
    fastcgi_param: 
        # 指明php文件的主目录, $fastcg_script_name 就是用户访问的 URI, 
    
    
    • 启动nginx
    [root@node10009 nginx]# /opt/app/nginx/sbin/nginx 
    

    END

    相关文章

      网友评论

          本文标题:Nginx 安装 以及连接PHP

          本文链接:https://www.haomeiwen.com/subject/ourlhqtx.html