Mac上使用brew安装Nginx服务器
使用brew安装nginx
$ brew install nginx
启动nginx
sudo nginx
访问localhost:8080 发现已出现nginx的欢迎页面了。

为方便期间,做个软连接:
sudo ln -s /usr/local/bin/nginx /usr/bin/nginx #我的mac没有成功,提示没有权限
常用的指令有:
nginx -V 查看版本,以及配置文件地址 nginx -v 查看版本 nginx -c filename 指定配置文件 nginx -h 帮助 打开 nginx sudo nginx nginx 重新加载配置|重启|停止|退出 nginx -s reload|reopen|stop|quit 测试配置是否有语法错误 nginx -t
例子:
MacBookPro:superlists apple$ ln -s /usr/local/bin/nginx /usr/bin/nginx ln: /usr/bin/nginx: Operation not permitted MacBookPro:superlists apple$ sudo nginx Password: MacBookPro:superlists apple$ nginx -v nginx version: nginx/1.10.2 MacBookPro:superlists apple$ nginx -V nginx version: nginx/1.10.2 built by clang 8.0.0 (clang-800.0.42.1) built with OpenSSL 1.1.0c 10 Nov 2016 TLS SNI support enabled configure arguments: --prefix=/usr/local/Cellar/nginx/1.10.2_1 --with-http_ssl_module --with-pcre --sbin-path=/usr/local/Cellar/nginx/1.10.2_1/bin/nginx --with-cc-opt='-I/usr/local/opt/pcre/include -I/usr/local/opt/openssl@1.1/include' --with-ld-opt='-L/usr/local/opt/pcre/lib -L/usr/local/opt/openssl@1.1/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module --with-ipv6

Nginx安装日志如下:
1 MacBookPro:superlists apple$ brew install nginx 2 Updating Homebrew... 3 ==> Auto-updated Homebrew! 4 Updated 1 tap (homebrew/core). 5 ==> New Formulae 6 cnats mingw-w64-binutils opencoarrays 7 imagemagick@6 molecule watchexec 8 ==> Updated Formulae 9 abcde gitup mongoose 10 afl-fuzz gnupg-pkcs11-scd openshift-cli 11 ansible godep orientdb 12 aria2 groonga pius 13 arping gtk+3 pngcrush 14 aws-sdk-cpp h2o pyenv 15 awscli htmlcleaner rocksdb 16 certbot httrack speedtest_cli 17 deis hyperscan sshguard 18 deisctl ios-webkit-debug-proxy swaks 19 docker-compose iso-codes swiftformat 20 docker-machine kobalt tcpkali 21 docker-machine-nfs libgcrypt tomcat 22 dpkg libgtop vim 23 eiffelstudio libtasn1 xz 24 fabio libxc yank 25 flow lighttpd yash 26 fossil logentries youtube-dl 27 fwup makeself 28 29 ==> Installing dependencies for nginx: pcre, openssl@1.1 30 ==> Installing nginx dependency: pcre 31 ==> Downloading https://homebrew.bintray.com/bottles/pcre-8.39.sierra.bottle.tar.gz 32 ######################################################################## 100.0% 33 ==> Pouring pcre-8.39.sierra.bottle.tar.gz 34 🍺 /usr/local/Cellar/pcre/8.39: 203 files, 5.4M 35 ==> Installing nginx dependency: openssl@1.1 36 ==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.0c.sierra.bottle.tar. 37 ######################################################################## 100.0% 38 ==> Pouring openssl@1.1-1.1.0c.sierra.bottle.tar.gz 39 ==> Using the sandbox 40 ==> Caveats 41 A CA file has been bootstrapped using certificates from the system 42 keychain. To add additional certificates, place .pem files in 43 /usr/local/etc/openssl@1.1/certs 44 45 and run 46 /usr/local/opt/openssl@1.1/bin/c_rehash 47 48 This formula is keg-only, which means it was not symlinked into /usr/local. 49 50 Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries 51 52 Generally there are no consequences of this for you. If you build your 53 own software and it requires this formula, you'll need to add to your 54 build variables: 55 56 LDFLAGS: -L/usr/local/opt/openssl@1.1/lib 57 CPPFLAGS: -I/usr/local/opt/openssl@1.1/include 58 59 ==> Summary 60 🍺 /usr/local/Cellar/openssl@1.1/1.1.0c: 6,225 files, 15.3M 61 ==> Installing nginx 62 ==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.2_1.sierra.bottle.1.tar.gz 63 ######################################################################## 100.0% 64 ==> Pouring nginx-1.10.2_1.sierra.bottle.1.tar.gz 65 ==> Caveats 66 Docroot is: /usr/local/var/www 67 68 The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that 69 nginx can run without sudo. 70 71 nginx will load all files in /usr/local/etc/nginx/servers/. 72 73 To have launchd start nginx now and restart at login: 74 brew services start nginx 75 Or, if you don't want/need a background service you can just run: 76 nginx 77 ==> Summary 78 🍺 /usr/local/Cellar/nginx/1.10.2_1: 8 files, 979.8K 79 MacBookPro:superlists apple$
本博客的内容如果没有标注转载字样,均属个人原创!采用知识共享署名 2.5 中国大陆许可协议进行许可。