安装部署Nginx

在虚拟机上安装CentOS7.4

去阿里云开源镜像站下载  我这下的是minimal版本的

设置完简体中文,安装位置确定一下,设置root密码

一开始很干净,连网卡IP地址也没有

修改网卡的IP    (Linux一切皆文件)

ONBOOT指的是操作系统运行以后,要不要把网卡启动起来   

重启网络服务,并ping一下   能成功平通

用Xshell链接一下   重新配置vi /etc/sysconfig/network-scripts/ifcfg-ens33  让他的IP地址从dhcp动态分配改为静态的

本人的nat模式下的网关为192.168.136.2

在重启一下网络服务  systemctl restart network

安装nginx  

Index of /download/

用xftp上传到/root目录下

[root@localhost ~]# tar zxvf nginx-1.21.6.tar.gz   #解压缩

 可以看到缺依赖   缺c语言编辑器

[root@localhost nginx-1.21.6]# yum install -y gcc

安装到指定的目录下 

[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx

还是缺依赖 

[root@localhost nginx-1.21.6]# yum install -y pcre pcre-devel

 

[root@localhost nginx-1.21.6]# yum install -y zlib zlib-devel
[root@localhost nginx-1.21.6]# ./configure --prefix=/usr/local/nginx 没有报错
[root@localhost nginx-1.21.6]# make
[root@localhost nginx-1.21.6]# make install

启动nginx

./nginx					    # 启动
./nginx -s stop			 	#快速停止
./nginx -s quit 			#优雅关闭,在退出前完成已经接受的连接请求
./nginx -s reload 			#重新加载配置

 关防火墙

[root@localhost sbin]# systemctl stop firewalld.service

安装成系统服务 

创建服务脚本

[root@localhost sbin]# vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重新加载系统服务

[root@localhost sbin]# systemctl daemon-reload

为了避免和原来的脚本冲突,先停nginx,再开启 

[root@localhost sbin]# ./nginx -s stop  #停止服务
[root@localhost sbin]# systemctl start nginx  #启动服务
[root@localhost sbin]# systemctl enable nginx.service  #设置开机启动

 

 

 

 

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fish_1112

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值