zoukankan      html  css  js  c++  java
  • centos7 编译安装nginx1.16.0( 完整版 )

    一、安装依赖包

    yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

      依赖包说明:

    1、编译依赖 gcc 环境,所以需要:gcc gcc-c++;

    2、PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库,所以需要:pcre pcre-devel ;

    3、zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库,所以需要:zlib zlib-devel ;

    4、OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库,所以需要:openssl openssl-devel ;

    二、从官网下载安装包

    wget https://nginx.org/download/nginx-1.16.0.tar.gz

    三、解压并安装

    tar zxvf nginx-1.16.0.tar.gz
    cd nginx-1.16.0
    ./configure --prefix=/usr/local/nginx
    make && make install

    四、测试安装是否成功

    [root@localhost ~]# nginx -V
    nginx version: nginx/1.16.0
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
    configure arguments: --prefix=/usr/local/nginx

    五、启动nginx服务

    cd /usr/local/nginx/sbin
    ./nginx

    六、验证服务是否启动成功

    [root@localhost sbin]# netstat -ntlp | grep nginx
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master 

    七、添加nginx服务

    vi /lib/systemd/system/nginx.service

      将以下内容插入:

    [Unit]
    Description=nginx
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    八、以服务的方式启动nginx

    pkill nginx
    systemctl start nginx

    九、查看服务是否启动

    [root@localhost sbin]# systemctl status nginx
    ● nginx.service - nginx
       Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
       Active: active (running) since Mon 2019-04-29 23:19:39 EDT; 18min ago
      Process: 348 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
     Main PID: 349 (nginx)
        Tasks: 2
       Memory: 976.0K
       CGroup: /system.slice/nginx.service
               ├─349 nginx: master process /usr/local/nginx/sbin/nginx
               └─350 nginx: worker process
    
    Apr 29 23:19:39 localhost.localdomain systemd[1]: Starting nginx...
    Apr 29 23:19:39 localhost.localdomain systemd[1]: Started nginx.
    [root@localhost sbin]# netstat -ntlp | grep nginx
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      349/nginx: master p 

    十、配置nginx服务自动启动

    [root@localhost sbin]# systemctl enable nginx
    Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
  • 相关阅读:
    Mac 系统环境变量配置
    sublime3+quick3.5 完整使用教程
    httprunner 2.5.7 下.env 文件环境变量的使用及debugtalk的使用,对test的参数化及执行
    python_request的安装及模拟json的post请求及带参数的get请求
    windows 下安装Charles,破解,安装证书,设置可抓取https包
    jmeter元件的执行顺序
    jmeter的参数化实现
    jmeter工作目录介绍、jmeter元件及组件介绍
    jmeter设置成中文显示
    win10下安装jmeter
  • 原文地址:https://www.cnblogs.com/yyxianren/p/10795120.html
Copyright © 2011-2022 走看看