brew 安装 Nginx

1、brew search nginx

$ brew search nginx
nginx
homebrew/nginx/accept-language-nginx-module                   homebrew/nginx/mogilefs-nginx-module
homebrew/nginx/accesskey-nginx-module                         homebrew/nginx/mp4-h264-nginx-module
homebrew/nginx/ajp-nginx-module                               homebrew/nginx/mruby-nginx-module
homebrew/nginx/anti-ddos-nginx-module                         homebrew/nginx/naxsi-nginx-module
homebrew/nginx/array-var-nginx-module                         homebrew/nginx/nchan-nginx-module
homebrew/nginx/auth-digest-nginx-module                       homebrew/nginx/nginx-full
homebrew/nginx/auth-ldap-nginx-module                         homebrew/nginx/notice-nginx-module
homebrew/nginx/auth-pam-nginx-module                          homebrew/nginx/php-session-nginx-module
homebrew/nginx/auto-keepalive-nginx-module                    homebrew/nginx/push-stream-nginx-module
homebrew/nginx/autols-nginx-module                            homebrew/nginx/realtime-req-nginx-module
homebrew/nginx/cache-purge-nginx-module                       homebrew/nginx/redis-nginx-module
homebrew/nginx/captcha-nginx-module                           homebrew/nginx/redis2-nginx-module
homebrew/nginx/counter-zone-nginx-module                      homebrew/nginx/rtmp-nginx-module
homebrew/nginx/ctpp2-nginx-module                             homebrew/nginx/set-misc-nginx-module
homebrew/nginx/dav-ext-nginx-module                           homebrew/nginx/small-light-nginx-module
homebrew/nginx/dosdetector-nginx-module                       homebrew/nginx/stream-lua-nginx-module
homebrew/nginx/echo-nginx-module                              homebrew/nginx/subs-filter-nginx-module
homebrew/nginx/eval-nginx-module                              homebrew/nginx/tcp-proxy-nginx-module
homebrew/nginx/extended-status-nginx-module                   homebrew/nginx/txid-nginx-module
homebrew/nginx/fancyindex-nginx-module                        homebrew/nginx/unzip-nginx-module
homebrew/nginx/geoip2-nginx-module                            homebrew/nginx/upload-nginx-module
homebrew/nginx/headers-more-nginx-module                      homebrew/nginx/upload-progress-nginx-module
homebrew/nginx/healthcheck-nginx-module                       homebrew/nginx/upstream-order-nginx-module
homebrew/nginx/http-accounting-nginx-module                   homebrew/nginx/ustats-nginx-module
homebrew/nginx/http-flood-detector-nginx-module               homebrew/nginx/var-req-speed-nginx-module
homebrew/nginx/http-remote-passwd-nginx-module                homebrew/nginx/vod-nginx-module
homebrew/nginx/log-if-nginx-module                            homebrew/nginx/websockify-nginx-module
homebrew/nginx/lua-nginx-module                               homebrew/nginx/xsltproc-nginx-module
homebrew/nginx/mod-zip-nginx-module

 

2、brew install nginx

$ brew install nginx
Updating Homebrew...
Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
New Formulae
qmmp
Updated Formulae
vaulted

Error: Could not link:
/usr/local/share/doc/homebrew

Please delete these paths and run `brew update`.
Installing dependencies for nginx: pcre, openssl@1.1
Installing nginx dependency: pcre
Downloading https://homebrew.bintray.com/bottles/pcre-8.40.sierra.bottle.tar.gz
######################################################################## 100.0%
Pouring pcre-8.40.sierra.bottle.tar.gz
/usr/local/Cellar/pcre/8.40: 204 files, 5.4MB
Installing nginx dependency: openssl@1.1
Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.0e.sierra.bottle.tar.gz
######################################################################## 100.0%
Pouring openssl@1.1-1.1.0e.sierra.bottle.tar.gz
Using the sandbox
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

This formula is keg-only, which means it was not symlinked into /usr/local.

This is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl@1.1/lib
    CPPFLAGS: -I/usr/local/opt/openssl@1.1/include

Summary
/usr/local/Cellar/openssl@1.1/1.1.0e: 6,303 files, 15.4MB
Installing nginx
Downloading https://homebrew.bintray.com/bottles/nginx-1.12.0.sierra.bottle.tar.gz
######################################################################## 100.0%
Pouring nginx-1.12.0.sierra.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.12.0: 8 files, 1002.3KB

从上述安装日志,可以得出:

1. nginx根目录为: Docroot is: /usr/local/var/www

2. nginx配置文件为: /usr/local/etc/nginx/nginx.conf

3. nginx 服务器路径: /usr/local/etc/nginx/servers/

 

启动 Nginx

sudo nginx 

 

访问 Nginx

http://localhost:8080

mac-os-x-install-nginx-01

出现nginx的欢迎页面了,nginx安装成功!

 

命令软链接

$ which nginx
/usr/local/bin/nginx

# /usr/bin/nginx 提示没权限,直接用 /usr/local/bin/nginx
$ ln -s  /usr/local/sbin/nginx /usr/local/bin/nginx  

 

Nginx 常用指令

nginx -V 查看版本,以及配置文件地址
nginx -v 查看版本
nginx -c filename 指定配置文件
nginx -h 帮助

$ nginx -V
nginx version: nginx/1.12.0
built by clang 8.1.0 (clang-802.0.42)
built with OpenSSL 1.1.0e  16 Feb 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.12.0 --with-http_ssl_module --with-pcre --sbin-path=/usr/local/Cellar/nginx/1.12.0/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 -v
nginx version: nginx/1.12.0
$ 
$ nginx -h
nginx version: nginx/1.12.0
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/Cellar/nginx/1.12.0/)
  -c filename   : set configuration file (default: /usr/local/etc/nginx/nginx.conf)
  -g directives : set global directives out of configuration file

 

Nginx 重启关闭

#重新加载配置|重启|停止|退出 nginx

nginx -s reload|reopen|stop|quit

 

#打开 nginx

sudo nginx

 

nginx 配置文件路径

vim /usr/local/etc/nginx/nginx.conf

 

#测试配置是否有语法错误

nginx -t

$ nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

 

Nginx 隐藏版本号

nginx 配置文件里增加 server_tokens off;

server_tokens作用域是http server location语句块

server_tokens默认值是on,表示显示版本信息,设置server_tokens值是off,就可以在所有地方隐藏nginx的版本信息。

vim /usr/local/etc/nginx/nginx.conf

mac-os-x-install-nginx-02

 

隐藏了 Nginx 版本号后,重启Nginx

nginx -s reload

nginx -s stop
nginx

mac-os-x-install-nginx-03

 

 

Mac 安装 brew

brew 官方网站: https://brew.sh

brew 安装方法: 

在Mac中打开Termal,输入命令:

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

install-software-mac-brew-01

当brew安装成功后,就可以随意安装自己想要的软件了,

例如wget,命令如下:

sudo brew install wget  

卸载命令如下:

sudo brew uninstall wget

查看安装软件的话,命令如下:

sudo brew search /apache*/

注意/apache*/是使用的正则表达式,用/分割。

 

 

参考推荐

CentOS 安装 Nginx

Nginx和PHP-FPM的启动、重启、停止脚本

LNMP(CentOS+Nginx+Mysql+PHP)服务器环境配置

Apache/Nginx/PHP 服务器隐藏版本号和系统

Nginx 反向代理及示例

Mac brew 安装软件