Mac安裝Nginx

1、檢查homebrew是否安裝,打開終端輸入命令

man brew

 

如已安裝,終端會輸出一些命令的幫助資訊,此時輸入Q退出即可

BREW(1)
NAME
brew - The missing package manager for macOS
SYNOPSIS
brew --version
brew command [--verbose|-v] [options] [formula] ...
DESCRIPTION
Homebrew is the easiest and most flexible way to install the UNIX tools
Apple didn't include with macOS.
ESSENTIAL COMMANDS
For the full command list, see the COMMANDS section.
With --verbose or -v, many commands print extra debugging information.
Note that these flags should only appear after a command.
install formula
Install formula.
uninstall formula
:

如沒安裝,點擊跳轉下載;

 

2、查看本機brew版本

brew --version

 

3、更新本機brew版本

brew --update

 

4、安裝Nginx

brew install nginx

出現以下資訊,表示安裝成功

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

 8080為默認埠。

查看nginx被安裝的目錄

查看nginx配置文件目錄   
open /usr/local/etc/nginx/

查看nginx被安裝到的目錄 
open /usr/local/Cellar/nginx 

 

5、啟動Nginx

nginx

驗證是否啟動成功

打開瀏覽器訪問:localhost:8080

出現如下圖,表示成功:

 

 

6、關閉Nginx

nginx -s stop