官网

选择Stable版本下载即可

安装方式

源码安装

  • 下载Nginx(其他下载方式亦可):wget https://nginx.org/download/nginx-1.20.1.tar.gz
  • 解压: tar -xf nginx-1.20.1.tar.gz
  • 进入源码目录:cd nginx-1.20.1
  • 查看编译配置 : ./configure --help
  • 安装依赖库: yum install pcre pcre-devel openssl openssl-devel -y
  • ./configure --with-http_ssl_module --with-http_v2_module --with-stream
  • 编译并安装: sudo make -j && make install
  • 加入环境变量: vi /etc/profile
  • 加入环境变量: 添加: export PATH=$PATH:/usr/local/nginx/sbin
  • 使生效 source /etc/profile
  • 加入system系统管理(顶格写): vi /usr/lib/systemd/system/nginx.service
  • 写入以下内容:
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target
  • 重载system服务: systemctl daemon-reload
  • 启动: systemctl start nginx