【Nginx】卸载以及怎么用源码进行安装?

目录

卸载

停止nginx

卸载nginx

 源码安装


卸载

停止nginx

检查nginx是否在运行

[root@localhost ~]# ps -ef | grep nginx
root       1753   1528  0 15:42 pts/0    00:00:00 grep --color=auto nginx
#停止nginx
[root@localhost ~]# /usr/sbin/nginx -s stop

忘记路径?

卸载nginx

执行命令 rm -rf *删除nignx安装的相关文件

如果在安装时设置了开机自启,还需要删除

再次进行查找没有关于nginx的文件

 再用yum指令进行删除

 删除完成

 源码安装

源码包获取:Index of /download/

官方教程安装: Building nginx from Sources

下载镜像,在这里我下载的是18.0

 ls查看,压缩包已经上传

 解压压缩包,放在了/usr/local/src

 创建系统用户

[root@localhost ~]# groupadd -r -g 996 nginx
[root@localhost ~]# useradd -r -u 997 -g 996 -s /sbin/nologin -M nginx

安装启动环境

[root@localhost nginx-1.18.0]# yum install gcc gcc-c++ make -y

查看模块帮助,会显示所有的模块,自行安装需要的模块

[root@localhost nginx-1.18.0]# ./configure --help | more

#选择了部分模块进行安装
[root@localhost nginx-1.18.0]# ./configure --user=nginx --group=nginx \
> --prefix=/usr/local/nginx \
> --with-http_ssl_module \
> --with-http_auth_request_module \
>  --with-http_gzip_static_module  \
> --with-http_gunzip_module \
> --with-http_stub_status_module 

出现问题:

 出现报错信息,原因是缺少http模块,所以缺什么补什么

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

继续执行模块添加,查看是否还有报错信息

还缺少OpenSSL模块,继续添加

[root@localhost nginx-1.18.0]# yum install openssl-devel -y

再次执行安装模块,出现总结的就安装好了

注意:进行复制,后边修改配置文件会方便一点

 进行编译

#加载的模块越多,加载的时间越长
make
make install

查看目录结构 

 配置启动脚本文件

[root@localhost nginx-1.18.0]# scp /usr/lib/systemd/system/nginx.service 192.168.75.120:/usr/lib/systemd/system/

用之前复制的修改自己的路径 

[Unit]
Description=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/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target
#重启服务,开机自启

[root@localhost nginx-1.18.0]# systemctl daemon-reload 
[root@localhost nginx-1.18.0]# systemctl enable --now nginx

[root@localhost nginx-1.18.0]# netstat -lnupt | grep -w 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*  

 出现successful,安装成功!

 源码安装:灵活,用什么模块装什么模块

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值