首先安装相应依赖包:
yum install gcc -c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
下载nginx包:
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
注:如果没有安装wget先安装
未安装wget报错信息:
-bash: wget: command not found
安装wget:
yum -y install wget
然后解压并进入:
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
进入nginx-1.16.0目录后,输入命令./configure,这个命令会在目录里生成Makefile文件:
./configure
如报错:-bash: ./configure: Permission denied为没有权限
输入命令:
bash ./configure
再输入make命令生成二进制文件
make
然后输入make install,把相关文件拷贝到对应的目录中,默认是/usr/local/nginx
make install
手动创建服务:
cd /etc/systemd/system
vi nginx.service
将以下内容复制到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
然后将nginx设置为开机启动:
systemctl enable nginx
完成了,最后需要重启服务器;