Nginx的安装启动和停止

Nginx介绍

       概述:Nginx是一个 HTTP 和反向代理服务器, 邮件代理服务器, 和通用的 TCP/UDP 代理服务器。

yum安装和编译安装

       简单来说,yum安装就是安装别人已经写好的包或模块,会自动解决相关的依赖,简单方便。
       编译安装是自己下载源码包,进行指定参数的设定,指定模块的安装,需要自己解决相关的包依赖。

Nginx编译安装

  1. 安装epel源,解决软件之间的相关依赖
yum install epel-release -y
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make psmisc net-tools lsof vim wget
  1. 新建一个用户,用它来启动一个nginx进程
useradd shengxia -s /sbin/nologin
  1. 新建文件夹,进入文件夹,下载软件安装包
mkdir /lianxi/nginx/shengxia -p
cd /lianxi/nginx/shengxia 
wget http://nginx.org/download/nginx-1.22.1.tar.gz
[root@localhost shengxia]# pwd
/lianxi/nginx/shengxia
  1. 解压进入解压目录,执行编译前的配置,指定安装路径,自己需要的安装模块
    必须要在nginx-1.22.1目录下才能执行./configure命令
#解压
tar xf nginx-1.22.1.tar.gz
cd nginx-1.22.1
#指定安装路径和模块
./configure --prefix=/usr/local/shengxia --user=shengxia --group=shengxia --with-http_ssl_module --with-threads --with-http_v2_module --with-http_stub_status_module --with-stream --with-http_gunzip_module
  1. 编译安装
#同时启动两个进程执行
make -j 2
#安装
make install
  1. 进入之间指定安装的目录,如果能发现以下文件夹,则说明安装成功
    在这里插入图片描述
  2. 启动nginx,进入/usr/local/shengxia/sbin,执行命令
[root@localhost sbin]# pwd
/usr/local/shengxia/sbin
[root@localhost sbin]# ./nginx 
  1. 查看nginx是否启动成功
    a.看端口,看是是否有80端口的进程
[root@localhost sbin]# netstat -anplut
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4658/nginx: master 

       b.看进程

[root@localhost sbin]# ps aux | grep nginx
root       4658  0.0  0.2  46372  2008 ?        Ss   22:16   0:00 nginx: master process /usr/local/shengxia/sbin/nginx
shengxia   4721  0.0  0.2  46812  2044 ?        S    22:29   0:00 nginx: worker process
root       7096  0.0  0.0 112824   980 pts/0    R+   23:39   0:00 grep --color=auto nginx

       c.看日志

[root@localhost logs]# pwd 
/usr/local/shengxia/logs
[root@localhost logs]# tail access.log

       d.直接访问
在这里插入图片描述
9. 修改PATH环境变量,方便在任何目录下都能使用nginx命令,同时关闭防火墙和selinux服务

echo "PATH=$PATH:/usr/local/shengxia/sbin" >>/root/.bashrc
#当前终端执行修改环境变量的脚本
source /root/.bashrc
#关闭防火墙,设置开机不启动
service firewalld stop
systemctl disable firewalld
#临时停止selinux和永久停止selinux
setenforce 0
sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
  1. 设置开机启动
chmod +x /etc/rc.d/rc.local
echo "/usr/local/shengxia/sbin/nginx" >>/etc/rc.local

Nginx关闭、重新启动和卸载

关闭

  1. 使用kill命令强制杀死nginx进程
[root@localhost conf]# ps aux | grep nginx
root       4658  0.0  0.2  46372  2008 ?        Ss   13:23   0:00 nginx: master process /usr/local/shengxia/sbin/nginx
shengxia   4721  0.0  0.2  46812  2284 ?        S    13:37   0:00 nginx: worker process
root       8861  0.0  0.0 112824   980 pts/0    R+   15:16   0:00 grep --color=auto nginx
[root@localhost conf]# kill -9 4658
  1. 使用nginx的-s参数关闭nginx,其实就是给nginx发送一个信号,然后执行
#快速关闭nginx
nginx -s stop
#优雅关闭nginx
nginx -s quit

重新启动
       当修改nginx配置文件时,可以使用nginx -t查看配置文件是否有错误,然后使用nginx -s reload重新加载配置文件,使用nginx -s reopen重新生成日志文件等。
卸载
       卸载主要删除之前指定的--prefix安装路径,然后删除写入PATH中的环境变量即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nginx启动停止可以通过以下命令进行操作: 1. 启动nginx:使用命令`start nginx.exe`来启动nginx。\[1\] 2. 停止nginx:使用命令`nginx.exe -s stop`来停止nginx。\[1\] 3. 重新加载nginx配置:使用命令`nginx.exe -s reload`来重新加载nginx的配置文件,使配置生效。这样可以避免先停止nginx启动nginx的步骤。\[2\] 需要注意的是,以上命令适用于Windows系统。对于Linux系统,可以使用`./nginx -s reload`命令来重新加载配置文件。\[2\] 此外,如果你想检查nginx的配置文件是否有问题,可以使用命令`nginx -t`来进行判断。例如,`nginx -t`命令可以检查配置文件`/usr/local/etc/nginx/nginx.conf`的语法是否正确,并返回测试结果。\[3\] #### 引用[.reference_title] - *1* [nginx启动停止和重启](https://blog.csdn.net/antch620/article/details/103008128)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [nginx启动命令和停止命令](https://blog.csdn.net/kongfanyu/article/details/128769528)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值