编译安装Nginx

作者: 养码哥 | 来源:发表于2018-02-04 12:32 被阅读43次
    1. 安装Nginx所需要的pcre库

    pcre的全程为perl compatible regular expressions,中文译为“perl兼容正则表达式”,官方站点为http://www.pcre.org,安装pcre库是为了使nginx支持具备URI重写功能的rewrite模块,如果不安装pcre库,则nginx无法使用rewrite模块功能,nginx的rewrite模块功能几乎是企业应用必须的。安装pcre库的过程如下。

    • 查看linux系统环境,命令如下:
    1. 采用yum安装方式安装pcre,命令如下:
    • yum install pcre pcre-devel -y
    1. yum安装操作后检查安装结果,命令如下
    • rpm -qa pcre pcre-devel

    安装nginx

    1.nginx软件有三种版本,稳定版,开发版和历史稳定版本,在实际工作中,选择稳定版本时,尽量避免使用最新的版本,选择比已出来的版本晚6-10个月的版本比较好。
    2.nginx的安装非常简单,具体的操作过程如下:
    检查并安装Nginx基础依赖包pcre-developenssl-devel
    要想正确安装Nginx,首先必须安装好pcre-developenssl-devel包,因此要先检查这些Nginx基础依赖包是否安装,命令如下:
    rpm -qa pcre pcre-devel

    rpm -qa openssl-devel openssl
    名称中带有devel字符串的软件包是必须要安装的。
    Nginx在使用https服务的时候要用到此模块,如果不安装openssl相关包,安装nginx的过程会报错。安装opnssl-devel及检查命令如下:
    yum install -y openssl openssl-devel
    rpm -qa openssl openssl-devel

    3.开始安装nginx
    操作命令如下:
    mkdir -p /home/helei/tools
    -p选项表示不提示目录是否存在,循环向下创建所有层级目录,如果存在就会忽略。
    cd /home/helei/tools/
    进入cd /home/helei/tools/目录
    wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
    下载软件包,进入http://nginx.org/download/ 复制对应版本的链接地址。提示如果发现nginx软件下载地址不可用,可能版本已更新,可去官网地址http://www.nginx.org下载。


    useradd nginx -s /sbin/nologin -M
    tar xf nginx-1.6.3.tar.gz
    cd nginx-1.6.3/
    ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with- http_stub_status_module --with-http_ssl_module
    make
    make install
    ln -s /application/nginx-1.6.3 /application/nginx
    这条ln 的命令的意义十分深远重大。生产环境
    将nginx安装路径通过软连接的方式更改为/application/nginx/,方便人员使用。
    安装时指定版本号路径是为了便于查看分区当前使用的nginx版本,也方便以后升级
    内部人员使用路径 /application/nginx/
    当nginx软件升级编译成带新版本号的版本后,删除原来的软连接,在重新建立到新的到/application/nginx/软连接就好
    程序中如果有引用nginx路径的地方,不需要做任何修改,因为升级后的访问路径还是 /application/nginx/

    cd ../
    检查链接及目录状态
    ll /application/ | grep nginx
    ls -l /application/nginx/
    ./configure--help查看相关参数或者参考nginx高性能web服务器详解
    在安装环节中如果遇到如下错误:
    ./configure: error: SSL modules require the OpenSSL library.
    You can either do not enable the modules, or install the OpenSSL library
    into the system, or build the OpenSSL library statically from the source
    with nginx by using --with-openssl=<path> option.

    解决方法:执行命令
    yum install openssl openssl-devel -y
    启动并检查nginx安装结果
    /application/nginx/sbin/nginx -t


    启动nginx服务
    /application/nginx/sbin/nginx

    查看nginx服务对应的端口是否成功启动,命令如下:
    /application/nginx/sbin/nginx
    查看nginx服务对应的端口是否成功启动
    lsof -i :80
    或者
    netstat -lnt | grep 80

    浏览器检查

    在linux下用wget命令检测
    wget 127.0.0.1

    curl命令检测
    curl 127.0.0.1


    推荐文章:https://www.jianshu.com/p/c798dac9b2ed

    相关文章

      网友评论

        本文标题:编译安装Nginx

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