1、下载nginx-1.16.1.tar.gz
使用命令下载:wget http://nginx.org/download/nginx-1.16.1.tar.gz
或百度网盘下载:https://pan.baidu.com/s/1eG7c7dNAi0uZ-0K827GNwQ提取码:z8i1
2、解压
tar -zxvf nginx-1.16.1.tar.gz
3、安装
nginx会默认安装到/usr/local/nginx目录下
切换到nginx-1.16.1/目录,安装需要的依赖库
yum install gcc-c++
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
执行命令:./configure
如果出现错误提示信息,需要正确安装依赖库
如果没有出现./configure: error提示,表示当前环境可以安装nginx,执行make和make install编译nginx
4、配置nginx开机启动
切换到/lib/systemd/system/目录,创建nginx.service文件vim nginx.service
cd /lib/systemd/system/
vim 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
退出并保存文件,执行systemctl enable nginx.service使nginx开机启动
systemctl enable nginx.service
systemctl start nginx.service启动nginx
systemctl stop nginx.service结束nginx
systemctl restart nginx.service重启nginx
5、验证是否安装成功
启动服务[默认80端口],访问:主机ip+port