1.准备工作
首先安装nginx需要的几个软件: GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL
安装命令如下;
yum install gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
使用gcc -v查看版本 检查是否安装成功
2.下载nginx
创建nginx目录: mkdir /usr/local/nginx
cd /usr/local
wget http://nginx.org/download/nginx-1.18.0.tar.gz
3.解压压缩包
tar -zxvf nginx-1.18.0.tar.gz
4.配置
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
5.编译&安装
make
make install
6.检测安装
cd /usr/loca/nginx/
./sbin/nginx -t
7.启动
cd /usr/local/nginx/sbin
./nginx
8.打开防火墙&永久开放端口
firewall-cmd --query-port=80/tcp
# 开放80端口 --permanent代表永久开启
firewall-cmd --add-port=80/tcp --permanent
#重启防火墙
systemctl restart firewalld
9. 配置nginx 开机启动
vim /etc/rc.d/rc.local
#添加如下:
#开机启动
/usr/local/nginx/sbin/nginx
10.为rc.local文件设置755权限
cd /etc/init.d/
chmod 755 rc.local
11.重启机器
reboot
12. 验证是否实现开机启动nginx
ps -ef|grep nginx