Centos7.5 nginx安装

安装nginx

1.官网下载地址:http://nginx.org/download/

博主是下载的nginx-1.15.8.tar.gz

2.上传至Linux系统的/home/bak/software

  [root@cicd ~]# mkdir -p /home/bak/software

-p 嵌套创建文件夹

3.解压缩

[root@cicd ~]# cd /home/bak/software
[root@cicd software]# tar -zxvf nginx-1.15.8.tar.gz

4.安装依赖工具

 [root@cicd ~]# yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel

5.添加用户组和用户

为了在黑客入侵时,减少损失,nginx不建议使用root用户进行登录

 [root@cicd ~]# groupadd web
 [root@cicd ~]# useradd -g web web

6.将 nginx-1.15.8移动至/opt目录下

[root@cicd software]# mv nginx-1.15.8 /opt/

7.创建软连接

[root@cicd opt]#ln -s nginx-1.15.8 nginx

8.添加配置文件

[root@cicd ~]#cd /opt/nginx
[root@cicd nginx]# ./configure --prefix=/opt/nginx --conf-path=/opt/nginx/nginx.conf --pid-path=/opt/nginx/conf/nginx.pid --user=web --group=web

9.编译及安装

[root@cicd nginx]# make
[root@cicd nginx]# make install

10.修改配置文件

[root@cicd nginx]# vi conf/nginx.conf

将server_name 默认的localhost修改为本机的ip地址
在这里插入图片描述
11.启动nginx

[root@cicd nginx]# ./sbin/nginx

然后,在本机的浏览器输入http://服务器的ip,出现如下界面,表示安装成功
在这里插入图片描述
12.关闭nginx

[root@cicd nginx]# ./sbin/nginx -s stop

配置自启动服务

1.在/etc/systemd/system/目录下创建nginx.service

[root@cicd ~]# vim /etc/systemd/system/nginx.service

2.添加如下内容

[Unit] 
Description=nginx 
After=network.target 
  
[Service] 
Type=forking 
ExecStart=/opt/nginx/sbin/nginx 
ExecReload=/opt/nginx/sbin/nginx -s reload 
ExecStop=/opt/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install] 
WantedBy=multi-user.target

3.设置开始自启动

systemctl enable nginx.service

这是需要提醒的是,配置完成后,使用systemctl status nginx查看nginx状态,显示Active: inactive (dead),不用惊讶。
这是因为配置的nginx.sevice文件未生效,杀死nginx进程重启nginx,问题解决。

ps -ef|grep nginx
kill -9 PID
systemctl start nginx

在这里插入图片描述
4.systemctl命令

#查看nginx状态
systemctl status nginx
#开启nginx
systemctl start nginx
#关闭nginx
systemctl stop nginx

5.确认进程关闭的三步骤

systemctl status nginx
ps -ef|grep nginx
netstat -ntlp|grep nginx

只有这三个命令都显示没有改进程,才能确定该进程真的被关闭了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值