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.
  • 相关阅读:
    CodeBlocks背景主题的设置
    Win7更改默认打开方式失败
    BAT命令介绍【转自Internet】
    Index of my articles
    一个表格说明RelativeLayout中的几个重要属性【Written By KillerLegend】
    有史以来最简单的三层实例(C#) ——转载自CSDN
    银联规定的MAC算法_转载
    Windows下ORACLE 10g安装与操作图解
    Oracle 在64位机器上使用PLSQL连接Oracle的问题(SQL * NET not properly installed)转载
    Linux系统下JDK和Tomcat安装配置
  • 原文地址:https://www.cnblogs.com/yyxianren/p/10795120.html
Copyright © 2011-2022 走看看