CentOS Linux release 7.8 编译安装 Nginx

CentOS Linux 系统使用 yum 安装的 Nginx 缺少一些需要的模块,只能用编译的方式来解决,记录一下安装过程。

首先需要用 yum 安装系统依赖:

sudo yum install -y gcc make \
    pcre-devel perl-ExtUtils-Embed openssl-devel

然后下载 nginx 源码:

wget -c http://nginx.org/download/nginx-1.18.0.tar.gz

解压并进入源码目录并按自己的需求执行编译操作:

tar zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0

./configure --prefix=/usr/local/nginx \
    --user=zzxworld \
    --group=zzxworld \
    --with-http_perl_module \
    --with-http_ssl_module \
    --with-http_v2_module

make

sudo make install

编译完成后,就可以使用 /usr/local/bin/bin/nginx 来管理 Nginx 了。不过更好的方式是使用 Systemd 服务。将 Nginx 接入 Systemd 也很简单,在 /usr/lib/systemd/system/ 目录创建一个 nginx.service 文件,内容如下:

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
  
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
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

然后就可以使用 systemctl 命令来管理 Nginx 了。

posted @ 2020-08-14 12:38  zzxworld  阅读(180)  评论(0编辑  收藏  举报