Mac下使用Home Brew安装Nginx

分类: 工作记录 0人评论 1年前发布

mac使用brew安装nginx记录

服务器上用nginx + tomcat做了负载均衡,在本地开发时图片等一系列文件上传操作多有不便,

想着本地也安装一个nginx,映射一下静态资源目录以便和项目分离。

Mac首选当然是用Home Brew来安装了。

使用命令:

selflydeMacBook-Pro:~ liyd$ brew install nginx

结果:

==> Installing dependencies for nginx: pcre
==> Installing nginx dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.38.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pcre-8.38.el_capitan.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/pkgconfig/libpcre.pc
/usr/local/lib/pkgconfig is not writable.

You can try again using:
brew link pcre
==> Summary
/usr/local/Cellar/pcre/8.38: 146 files, 5.4M
==> Installing nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.8.1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
......

虽然提示已经安装了,但是出现了错误信息,应该是哪里没对,尝试卸载重装

selflydeMacBook-Pro:~ liyd$ brew uninstall nginx
Uninstalling /usr/local/Cellar/nginx/1.8.1... (7 files, 946.2K)
selflydeMacBook-Pro:~ liyd$
selflydeMacBook-Pro:~ liyd$ brew install nginx
Error: You must `brew link pcre` before nginx can be installed
selflydeMacBook-Pro:~ liyd$

直接不能安装了,根据错误提示brew link pcre

selflydeMacBook-Pro:~ liyd$ brew link pcre
Linking /usr/local/Cellar/pcre/8.38...
Error: Could not symlink lib/pkgconfig/libpcre.pc
/usr/local/lib/pkgconfig is not writable.

一开始以为是缺少pkgconfig,安装后再试

selflydeMacBook-Pro:~ liyd$ brew install pkgconfig
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.el_capitan.bottle.tar.gz
/usr/local/Cellar/pkg-config/0.29: 10 files, 624.4K
selflydeMacBook-Pro:~ liyd$
selflydeMacBook-Pro:~ liyd$ brew link pcre
Linking /usr/local/Cellar/pcre/8.38...
Error: Could not symlink lib/pkgconfig/libpcre.pc
/usr/local/lib/pkgconfig is not writable.

依旧报错,查看pkgconfig

selflydeMacBook-Pro:~ liyd$ ll /usr/local/lib/pkgconfig/
total 16
lrwxr-xr-x  1 root  wheel   10  3  7 15:45 fuse.pc -> osxfuse.pc
-rw-r--r--  1 root  wheel  276  1 18 15:31 osxfuse.pc

看样子应该是没有权限,给当前用户授权再试,成功

selflydeMacBook-Pro:~ liyd$ chown liyd /usr/local/lib/pkgconfig/
chown: /usr/local/lib/pkgconfig/: Operation not permitted
selflydeMacBook-Pro:~ liyd$ sudo chown liyd /usr/local/lib/pkgconfig/
Password:
selflydeMacBook-Pro:~ liyd$ brew link pcre
Linking /usr/local/Cellar/pcre/8.38... 133 symlinks created

之后再安装nginx,不再有错误信息

elflydeMacBook-Pro:~ liyd$ brew install nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.8.1.el_capitan.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/nginx-1.8.1.el_capitan.bottle.tar.gz
==> Pouring nginx-1.8.1.el_capitan.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/www

The 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 at login:
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
nginx
==> Summary
/usr/local/Cellar/nginx/1.8.1: 7 files, 946.2K
selflydeMacBook-Pro:~ liyd$

从上面信息可以看出:

  • nginx默认web目录是/usr/local/var/www

  • 默认配置文件是/usr/local/etc/nginx/nginx.conf,并会加载/usr/local/etc/nginx/servers/目录下的所有配置

  • 默认端口是8080

上一篇:
下一篇:

你可能感兴趣的文章

0 条评论