nginx在MAC上的安装、启动、重启和关闭

一、安装

执行如下命令

brew search nginx

brew install nginx

安装完以后,可以在终端输出的信息里看到一些配置路径:

/usr/local/etc/nginx/nginx.conf (配置文件路径)

/usr/local/var/www (服务器默认路径)

/usr/local/Cellar/nginx/1.8.0 (安装路径)

如果是macOS 1.12以上的系统,在安装过程中可能会出现"warning",说是不支持该版本的操作系统,可以暂时先忽略它。


二、启动

在终端中输入

ps -ef|grep nginx

如果执行的结果是

  501 15800     1   0 12:17上午 ??         0:00.00 nginx: master process /usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf  

  501 15801 15800   0 12:17上午 ??         0:00.00 nginx: worker process  

  501 15848 15716   0 12:21上午 ttys000    0:00.00 grep nginx


表示已启动成功,如果不是上图结果,在终端中执行

/usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf

命令即可启动nginx。

这时候如果成功访问localhost:8080,说明成功安装和启动好了。

、停止

在终端中输入 ps -ef|grep nginx  获取到nginx的进程号,注意是找到“nginx:master”的那个进程号,如下面的进程好是 15800

  501 15800     1   0 12:17上午 ??         0:00.00 nginx: master process /usr/local/Cellar/nginx/1.8.0/bin/nginx -c /usr/local/etc/nginx/nginx.conf  

  501 15801 15800   0 12:17上午 ??         0:00.00 nginx: worker process  

  501 15848 15716   0 12:21上午 ttys000    0:00.00 grep nginx


在终端中输入以下几种命令都可以停止

kill -QUIT  15800 (从容的停止,即不会立刻停止)

Kill -TERM  15800 (立刻停止

Kill -INT  15800  (和上面一样,也是立刻停止


四、重启

如果配置文件错误,则将启动失败,所以在启动nginx之前,需要先验证在配置文件的正确性,如下表示配置文件正确

promote:bin yangqianhua$ /usr/local/Cellar/nginx/1.8.0/bin/nginx -t -c /usr/local/etc/nginx/nginx.conf

nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok

nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

重启有两种方法

1)在终端输入输入如下命令即可重启

promote:~ yangqianhua$ cd /usr/local/Cellar/nginx/1.8.0/bin/

promote:bin yangqianhua$ ./nginx -s reload

promote:bin yangqianhua$ 


2)根据进程号重启,执行命令 kill -HUP 进程号
  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值