centos7安装nginx并设置开机启动

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值