从nginx官网下载stable version安装包
wget http://nginx.org/download/nginx-1.16.0.tar.gz
安装依赖库
yum install gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
解压nginx安装包
tar -zxvf nginx-1.16.0.tar.gz
进入到nginx目录,对安装的软件进行配置以及检查当前的环境是否满足要安装软件的依赖关系
./configure
源码编译
make
安装nginx
make install
配置nginx系统服务
vim /lib/systemd/system/nginx.service
nginx.service文件中内容
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=
/usr/local/nginx/sbin/nginx
ExecReload=
/usr/local/nginx/sbin/nginx
reload
ExecStop=
/usr/local/nginx/sbin/nginx
quit
PrivateTmp=
true
[Install]
WantedBy=multi-user.target
在/lib/systrm/system/目录下,设为开机自启
systemctl enable nginx.service
启动|关闭|重启nginx
systemctl start|stop|restart nginx.service
关闭防火墙(默认80端口关闭,也可以开启80端口)
systemctl stop firewalld.service
设为开机不自启
systemctl disable firewalld.service
验证安装成功,出现"welcome to nginx"界面
http;//nginxServerIP