1.下载nginx:
地址:http://nginx.org/en/download.html
2.安装依赖
安装gcc:
yum install -y gcc
安装pcre库
yum install -y pcre pcre-devel
安装zlib库:
yum install -y zlib zlib-devel
3.安装nginx
./configure --prefix=/usr/local/nginx
make
make install
4.启动nginx
.nginx #启动服务
.nginx -s stop #停止服务
.nginx -s quit #优雅关闭服务,结束前完成已接受的链接请求
.nginx -s reload #重新加载配置文件
5.打开防火墙
firewall-cmd --permanent --add-service=http --zone=public
firewall-cmd --reload
6.安装成系统服务
创建服务脚本:
vim /usr/lib/systemd/system/nginx.service
脚本内容:
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
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
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true[Install]
WantedBy=multi-user.target
7.设置开机启动
systemctl daemon-reload
systemctl enable nginx