1. 安装必要插件
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.下载指定版本的nginx源码压缩包
- 一种方式是从从nginx官网http://nginx.org/en/download.html下载,上传到指定文件路径保存
- 一种方式是命令直接下载
wget http://nginx.org/download/nginx-1.18.0.tar.gz
3.解压下载好的文件
tar -zxvf nginx-1.18.0.tar.gz
4.进入到解压后的文件夹内指定安装路径
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream
5.编译nginx源码
make
6.安装nginx
make install
7.创建服务
cd /etc/systemd/system
创建nginx.service文件
vi nginx.service
复制以下内容并保存
[UNIT]
Deion=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=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
8.将nginx设置为开机启动
systemctl enable nginx
9.启动nginx服务
systemctl start nginx
10.在浏览器中测试nginx
如果安装成功可以看到nginx欢迎信息