每次安装完都忘记具体的安装目录。
不像在 Linux 下,/usr/local/nginx/ (PS:估计也是习惯问题)
这里命令网上一抓一大把,这里只是记录一下,方便自己查看,要不每次都得搜索
安装命令
brew install nginx
- 如未安装 Homebrew,需安装 Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装完,直接 sudo nginx 启动,浏览器访问 localhost:8080,如访问成功即可。
- 安装目录:/usr/local/Cellar/nginx/1.13.10
- 文件配置:/usr/local/etc/nginx
- LOG日志:/usr/local/var/log/nginx
- 网站根目录:/usr/local/var/www
- /usr/local/Cellar/nginx/1.13.10/html (其实是一样的,这是软连接)
常用命令
- 查看版本号以及安装目录:nginx -V
- 只看版本号:nginx -v
sudo nginx -t # 检测配置文件
sudo nginx # 开启nginx服务
sudo nginx -s stop # 停止
sudo nginx -s reload # 重新加载配置文件,相当于平滑重启
- 可以查看进程来进行结束掉进程
ps -ef | grep nginx
kill -QUIT 进程ID (从容的停止,即不会立刻停止)
Kill -TERM 进程ID (立刻停止)
Kill -INT 进程ID (和上面一样,也是立刻停止)
问题
sudo nginx -s reload
重新加载提示报错,提示没有 nginx.pid 文件。
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
解决
- 使用
nginx -c
的参数指定 nginx.conf 文件的位置
sudo /usr/local/Cellar/nginx/1.13.10/bin/nginx -c /usr/local/etc/nginx/nginx.conf