mac brew install nginx遇到的坑

默认使用 brew install nginx 出现了一下的错误:

 

localhost:testdj newstart$ brew install nginx

==> Installing dependencies for nginx: openssl, pare

==> Installing nginx dependency: openssl

==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2n.high_sierra.

######################################################################## 100.0%

==> Pouring openssl-1.0.2n.high_sierra.bottle.tar.gz

Error: Failed to create /usr/local/opt/openssl

Things that depend on openssl will probably not build.

Could not symlink .

/usr/local/opt is not writable.

Warning: The post-install step did not complete successfully

You can try again using `brew postinstall openssl`

==> 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/certs

 

and run

  /usr/local/opt/openssl/bin/c_rehash

 

This 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_profile

 

For compilers to find this software you may need to set:

    LDFLAGS:  -L/usr/local/opt/openssl/lib

    CPPFLAGS: -I/usr/local/opt/openssl/include

 

==> Summary

🍺  /usr/local/Cellar/openssl/1.0.2n: 1,792 files, 12.3MB

==> Installing nginx dependency: pcre

==> Downloading https://homebrew.bintray.com/bottles/pcre-8.41.high_sierra.bottl

######################################################################## 100.0%

==> Pouring pcre-8.41.high_sierra.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 .

/usr/local/opt is not writable.

 

You can try again using:

  brew link pcre

==> Summary

🍺  /usr/local/Cellar/pcre/8.41: 204 files, 5.3MB

==> Installing nginx

==> Downloading https://homebrew.bintray.com/bottles/nginx-1.12.2_1.high_sierra.

######################################################################## 100.0%

==> Pouring nginx-1.12.2_1.high_sierra.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 .

/usr/local/opt is not writable.

 

You can try again using:

  brew link nginx

Warning: The post-install step did not complete successfully

You can try again using `brew postinstall nginx`

==> 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 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.12.2_1: 25 files, 1MB

localhost:testdj newstart$ /usr/local/webserver/nginx/sbin/nginx -v

-bash: /usr/local/webserver/nginx/sbin/nginx: No such file or directory

localhost:testdj newstart$ /usr/local/Cellar/nginx/sbin/nginx -v

-bash: /usr/local/Cellar/nginx/sbin/nginx: No such file or directory

localhost:testdj newstart$ brew postinstall nginx

==> Postinstalling nginx

Error: Permission denied @ dir_s_mkdir - /usr/local/etc

localhost:testdj newstart$ sudo chown -R $(whoami) /usr/local/etc/

chown: /usr/local/etc/: No such file or directory

localhost:testdj newstart$ sudo chown -R $(whoami) /usr/local

chown: /usr/local: Operation not permitted

localhost:testdj newstart$ sudo chown -R $(whoami) /usr/local/

chown: /usr/local/: Operation not permitted

localhost:testdj newstart$ nginx

-bash: nginx: command not found

localhost:testdj newstart$ sudo nginx

sudo: nginx: command not found

localhost:testdj newstart$ 

 

 

然后就是浩浩荡荡的解决之路:

 

首先如果出现一些目录没有权限的问题:直接使用  sudo chown -R $(whoami) /usr/local/opt(这个目录就是需要赋予权限的目录),往后所有需要给目录赋权限的使用,直接使用这个,比如,提示Error: Failed to create /usr/local/opt/openssl 直接使用上面的命令

 

1. openssl 无法link成功

在试过很多方法之后,比如 添加 --force 参数,仍旧无解的情况下,google给了我希望

删除 /usr/local/Cellar/openssl路径,可是删除之后重新使用 brew install openssl 仍旧失败

继续,删除 rm -rf /usr/local/opt/openssl

重新使用 brew install openssl。成功

2. 启动nginx 仍旧失败

查看只有发现是 没有 link pcre

使用命令:brew link pcre

3. 这样修改之后,仍旧失败

启动后,显示

nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (2: No such file or directory)

2017/12/26 15:47:00 [emerg] 36666#0: open() "/usr/local/nginx/conf/nginx.conf" failed (2: No such file or directory)

这个时候,执行 brew postinstall nginx

解决

4. 访问 localhost:8080 显示成功

 

posted @ 2017-12-26 16:07  begeeeeeeek  阅读(10560)  评论(1编辑  收藏  举报