brew包更新
建议brew update,否则安装可能有问题
brew update 特别慢时,可以切换阿里源镜像(也可以切换中科大、清华镜像)
cd "$(brew --repo)"
git remote set-url origin Index of /homebrew/brew.git/
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin Index of /homebrew/homebrew-core.git/
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
brew update
brew update 可能会报错 Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-xxx failed!
解决方案:
在终端中依次执行sudo chown -R apple:staff *和brew doctor两个命令如下图:
localhost:~ sant$ sudo chown -R apple:staff *
localhost:~ sant$ brew doctor
在终端执行
sudo chown -R apple:staff
命令时 会提示 chown: apple: illegal user name
出现这个提示的原因是找不到apple 这个用户
解决方案也很简单:
在终端中执行 whoami 命令,查询当前用户的名称,
将 sudo chown -R apple:staff 中的apple 替换成查询出的用户名,运行该命令;
安装nginx
执行安装命令
brew install nginx
安装完成nginx以后cd到相应目录
cd /usr/local/Cellar/nginx/1.19.1/bin/
执行
./nginx
这时候如果在浏览器能够访问localhost:8080则已经安装成功了
配置环境变量
现在nginx已经安装完成,但是每次启动nginx都要cd到“/usr/local/Cellar/nginx/1.19.1/bin/”不太友好,所以需要配置环境变量
执行以下命令
sudo vim /etc/profile
在文件底部添加一行
export PATH=$PATH:/usr/local/Cellar/nginx/1.19.1/bin
执行
:wq!
退出编辑,然后再执行以下命令,可以使文件的改动生效
source /etc/profile
现在启动nginx只需要执行
nginx
另外
nginx -s stop #停止nginx
nginx -s reload #重新加载nginx
如果需要更改配置文件,配置文件路径 /usr/local/etc/nginx/nginx.conf
卸载nginx
nginx -s stop 停止nginx进程
which nginx 查看nginx所在目录 删除
brew remove nginx