1、安装前准备
Nginx依赖的必备插件有4个:
- gcc
- pcre
- zlib
- openssl
插件在线安装方案:
yum -y install gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
离线安装插件:
# 插件下载地址
ftp://ftp.pcre.org:21/pub/pcre/pcre-8.45.tar.gz
http://zlib.net/zlib-1.2.11.tar.gz
https://www.openssl.org/source/openssl-1.1.1k.tar.gz
# 安装pcre
tar -zxvf pcre-8.45.tar.gz
cd pcre-8.45
./configure
make && make install
# 安装zlib
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
# 安装openssl
tar -zxvf openssl-1.1.1k.tar.gz
cd openssl-1.1.1k
./config
make && make install
2、安装Nginx
将Nginx安装包nginx-1.18.0.tar.gz上传到/usr/local/目录下
解压安装
# 解压
tar -zxvf nginx-1.18.0.tar.gz
# 进入根目录
cd nginx-1.18.0
# 编译安装
./configure --prefix=/usr/local/nginx
# 注意:如需使用SSL模块,需要加上 --with-http_ssl_module
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
3、添加系统服务
vim /usr/lib/systemd/system/nginx.service
# 添加如下内容
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
设置开机启动
systemctl enable nginx