Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

源码安装(不推荐)

  • 提前安装依赖库(以centos为例,如果ubuntu可以把 yum 改成 apt-get )

    • gcc环境
      sudo yum -y install gcc gcc-c++
      
    • pcre
      sudo yum -y install pcre pcre-devel
      
    • zlib
      sudo yum -y install zlib zlib-devel 
      
    • openssl
      sudo yum -y install openssl openssl-devel
      
  • 新建目录/usr/local/nginx,并进入

    • 下载源码包
      wget https://nginx.org/download/nginx-1.20.2.tar.gz
      
      • 目前稳定版为1.20.2
      • 可以在nginx: download找到最新稳定版下载地址
    • 解压
      sudo tar -zxvf nginx-1.20.2.tar.gz
      
    • 进入目录
      cd nginx-1.20.2
      
    • 编译配置,并指定安装目录
      ./configure --prefix=/usr/local/nginx
      
    • 正式编译
      make
      
    • 安装
      make install
      
  • 运维

    • 查看配置
      vim /usr/local/nginx/nginx.conf
      
    • 启动
      /usr/local/nginx/sbin/nginx
      
    • 测试配置文件正确性
      /usr/local/nginx/sbin/nginx -t
      
    • 重载
      /usr/local/nginx/sbin/nginx -s reload
      
    • 停止
      /usr/local/nginx/sbin/nginx -s stop
      
  • 如果觉得输入上面一长串太麻烦,可以指定环境变量

    • vim /etc/profile编辑文件
    • 添加如下内容
      export NGINX_HOME= /usr/local/nginx
      export PATH=$PATH:$NGINX_HOME/sbin
      
    • 然后重启终端,以后直接输nginx即可