zoukankan      html  css  js  c++  java
  • yum和源码编译安装nginx

    yum和编译安装nginx

    官方安装文档http://nginx.org/en/linux_packages.html#RHEL-CentOS

    一、yum方式安装(root用户)

    1、添加nginx源

    rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    
    • 也可安装官方文档所示手动创建nginx源配置

     

    2、安装nginx**

    • 通过yum search nginx看看是否已经添加源成功
    yum install -y nginx
    

    3、启动nginx

    systemctl start nginx.service
    

    二、源码编译安装

    1、下载nginx源码

    官方地址:https://nginx.org/en/download.html

    # 浏览下载或用wget下载
    wget https://nginx.org/download/nginx-1.20.2.tar.gz
    

    2、安装依赖环境

    如果不安装依赖,在检查配置时会报错

    • 安装 gcc,安装 Nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境

      yum install -y gcc-c++
      
    • 安装 PCRE pcre-devel,PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。

      yum install -y pcre pcre-devel
      
    • 安装 zlib,zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 linux 上安装 zlib 库。

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

       yum install -y openssl openssl-devel
      

    3、解压nginx源码包

    tar -zxvf nginx1.20.2.tar.gz
    

    4、配置

    # 进入解压完的目录
    cd  nginx1.20.2
    
    • 默认安装路径
    # 配置
    ./configure
    
    • 自定义安装路径配置,配置 安装路径(--prefix)配置文件路径(--conf-path)运行进程文件路径(--pid-path)进程锁路径(--lock-path)

      # 配置
      ./configure \
      --prefix=/usr/local/nginx \
      --conf-path=/usr/local/nginx/conf/nginx.conf \
      --pid-path=/usr/local/nginx/conf/nginx.pid \
      --lock-path=/usr/local/nginx/lock/nginx.lock
      

    5、编译安装

    make
    make install
    

    6、启动nginx

    # 根据安装路径--prefix启动
    /usr/local/nginx/sbin/nginx
    
    # 查看nginx进程
    ps -ef | grep nginx
    

    博客内容仅供参考,部分参考他人优秀博文,仅供学习使用
  • 相关阅读:
    [leetcode ]429. N-ary Tree Level Order Traversale (easy)
    [leetcode] 559. Maximum Depth of N-ary Tree (easy)
    [leetcode] 406. Queue Reconstruction by Height (medium)
    [leetcode] 238. Product of Array Except Self (medium)
    [leetcode] 94. Binary Tree Inorder Traversal
    [leetcode] 621. Task Scheduler(medium)
    [leetcode] 309. Best Time to Buy and Sell Stock with Cooldown(medium)
    为窗口设置图标
    关闭住主窗口
    窗口居中显示
  • 原文地址:https://www.cnblogs.com/linagcheng/p/15661474.html
Copyright © 2011-2022 走看看