热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Nginx安装启动停止重启

一、安装(MacOS)执行brewsearchnginx和brewinstallnginx命令:$brewsearchnginxSearchinglocaltap

一、安装(Mac OS)

  执行 brew search nginx 和 brew install nginx 命令:

$ brew search nginx
==> Searching local taps...
nginx
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...

$ brew install nginx
==> Installing dependencies for nginx: openssl, pcre
==> Installing nginx dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.high_sierr
######################################################################## 100.0%
==> Pouring openssl-1.0.2o_1.high_sierra.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped
using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added
in
the System keychain), place .pem files
in/usr/local/etc/openssl/certsand run/usr/local/opt/openssl/bin/c_rehashThis formula is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL
in favor of its own TLS and crypto libraries.If you need to have this software first in your PATH run:echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profileFor compilers to find this software you may need to set:LDFLAGS: -L/usr/local/opt/openssl/libCPPFLAGS: -I/usr/local/opt/openssl/include==> Summary
?
/usr/local/Cellar/openssl/1.0.2o_1: 1,791 files, 12.3MB
==> Installing nginx dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.42.high_sierra.bottl
######################################################################## 100.0%
==> Pouring pcre-8.42.high_sierra.bottle.tar.gz
?
/usr/local/Cellar/pcre/8.42: 204 files, 5.3MB
==> Installing nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.13.11.high_sierra.b
######################################################################## 100.0%
==> Pouring nginx-1.13.11.high_sierra.bottle.tar.gz
==> Caveats
Docroot
is: /usr/local/var/wwwThe default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.nginx will load all files
in /usr/local/etc/nginx/servers/.To have launchd start nginx now and restart at login:brew services start nginx
Or,
if you don't want/need a background service you can just run:
nginx
==> Summary
?
/usr/local/Cellar/nginx/1.13.11: 23 files, 1.4MB

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

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

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

  安装路径: /usr/local/Cellar/nginx/1.13.11

 

二、启动

  执行 ps -ef|grep nginx 命令:(直接执行 nginx 也可以 命令行看上去没效果,但是已经启动)

$ ps -ef|grep nginx501 3178 1 0 1:38下午 ?? 0:00.00 nginx: master process nginx501 3179 3178 0 1:38下午 ?? 0:00.00 nginx: worker process501 3183 1595 0 1:39下午 ttys039 0:00.00 grep nginx

  表示已启动成功,如果不是上面结果,在终端中执行 /usr/local/Cellar/nginx/1.13.11/bin/nginx -c /usr/local/etc/nginx/nginx.conf 命令即可启动nginx。

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

 

三、停止

  输入 启动命令(ps -ef|grep nginx) 获取到nginx的进程号,注意是找到“nginx:master”的那个进程号,如上是 3178。

  以下几种命令都可以停止:

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

    Kill -TERM 3178 (立刻停止)

    Kill -INT 3178 (立刻停止)

 

四、重启

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

$ /usr/local/Cellar/nginx/1.13.11/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. $ /usr/local/Cellar/nginx/1.13.11/bin/nginx -s reload  或者 $ cd /usr/local/Cellar/nginx/1.13.11/bin $ ./nginx -s reload

    2. 根据进程号重启,执行命令 kill -HUP 进程号。


转载于:https://www.cnblogs.com/pinweyshg/p/8820091.html


推荐阅读
author-avatar
翌佳际_984
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有