mac下nginx安装与使用

1、确认你的电脑是否安装homebrew,打开电脑终端 :

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、

brew -v

srtdeMacBook-Pro:~ srt$ brew -v

Homebrew 2.2.2

Homebrew/homebrew-core (git revision 4710; last commit 2019-12-23)

 说明成功

3、brew install nginx

Updating Homebrew...

Error: The following directories are not writable by your user:

/usr/local/share/man/man3

/usr/local/share/man/man5

/usr/local/share/man/man7

You should change the ownership of these directories to your user.

  sudo chown -R $(whoami) /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7

And make sure that your user has write permission.

  chmod u+w /usr/local/share/man/man3 /usr/local/share/man/man5 /usr/local/share/man/man7

按提示操作

继续

 brew install nginx

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

4、输入下面命令 出现版本号表示成功

nginx -v

nginx version: nginx/1.17.10

5、总结:关键自动下载安装点 及含义

==> Installing dependencies for nginx: openssl@1.1 and pcre

==> Installing nginx dependency: openssl@1.1

==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1f.catalina

==> Downloading from https://akamai.bintray.com/72/724cd97c269952cdc28e24798e350

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

==> Pouring openssl@1.1-1.1.1f.catalina.bottle.tar.gz

==> Caveats

A CA file has been bootstrapped using certificates from the system

keychain. To add additional certificates, place .pem files in

  /usr/local/etc/openssl@1.1/certs

and run

  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,

because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:

  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:

  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"

  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary

🍺  /usr/local/Cellar/openssl@1.1/1.1.1f: 8,057 files, 18MB

==> Installing nginx dependency: pcre

==> Downloading https://homebrew.bintray.com/bottles/pcre-8.44.catalina.bottle.t

==> Downloading from https://akamai.bintray.com/f8/f8ac266e04f984fa55091a43f0fdc

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

==> Pouring pcre-8.44.catalina.bottle.tar.gz

🍺  /usr/local/Cellar/pcre/8.44: 204 files, 5.5MB

==> Installing nginx

==> Downloading https://homebrew.bintray.com/bottles/nginx-1.17.10.catalina.bott

==> Downloading from https://akamai.bintray.com/f5/f53fc4b6f3dc7fd955a67c9b7fa02

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

==> Pouring nginx-1.17.10.catalina.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 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.17.10: 25 files, 2.1MB(安装路径)

==> `brew cleanup` has not been run in 30 days, running now...

Removing: /Users/srt/Library/Caches/Homebrew/telnet--60.mojave.bottle.tar.gz... (52.5KB)

Removing: /Users/srt/Library/Logs/Homebrew/telnet... (64B)

Pruned 3 symbolic links and 3 directories from /usr/local

==> Caveats

==> openssl@1.1

A CA file has been bootstrapped using certificates from the system

keychain. To add additional certificates, place .pem files in

  /usr/local/etc/openssl@1.1/certs

and run

  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,

because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:

  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl@1.1 you may need to set:

  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"

  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> nginx

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

6、启动:

  brew services start nginx

访问 localhost:8080 

ps -ef | grep nginx

  501 91689     1   0  3:25下午 ??         0:00.02 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;  

  501 91692 91689   0  3:25下午 ??         0:00.01 nginx: worker process  

  501 91831 40643   0  3:37下午 ttys000    0:00.01 grep nginx

 

sers srt$ ps aux | grep nginx

srt              91914   0.0  0.0  4277496    664 s000  S+    3:45下午   0:00.00 grep nginx

srt              91692   0.0  0.0  4300748    948   ??  S     3:25下午   0:00.01 nginx: worker process  

srt              91689   0.0  0.0  4292116   1712   ??  S     3:25下午   0:00.02 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;  

srtdeMacBook-Pro:Users srt$ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值