前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Mac OS X 安装 Nginx

Mac OS X 安装 Nginx

作者头像
阳光岛主
发布2019-02-18 15:00:40
2K0
发布2019-02-18 15:00:40
举报
文章被收录于专栏:米扑专栏

brew 安装 Nginx

1、brew search nginx

12345678910111213141516171819202122232425262728293031

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

2、brew install nginx

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263

$ brew install nginxUpdating Homebrew...Auto-updated Homebrew!Updated 1 tap (homebrew/core).New FormulaeqmmpUpdated Formulaevaulted Error: Could not link:/usr/local/share/doc/homebrew Please delete these paths and run `brew update`.Installing dependencies for nginx: pcre, openssl@1.1Installing nginx dependency: pcreDownloading 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.4MBInstalling nginx dependency: openssl@1.1Downloading 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.gzUsing the sandboxCaveatsA CA file has been bootstrapped using certificates from the systemkeychain. 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.4MBInstalling nginxDownloading https://homebrew.bintray.com/bottles/nginx-1.12.0.sierra.bottle.tar.gz######################################################################## 100.0%Pouring nginx-1.12.0.sierra.bottle.tar.gzCaveatsDocroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so thatnginx 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 nginxOr, if you don't want/need a background service you can just run:  nginxSummary/usr/local/Cellar/nginx/1.12.0: 8 files, 1002.3KB

启动 Nginx

sudo nginx 

访问 Nginx

http://localhost:8080

mac-os-x-install-nginx-01
mac-os-x-install-nginx-01

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

命令软链接

12345

$ 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 帮助

12345678910111213141516171819202122232425

$ nginx -Vnginx version: nginx/1.12.0built by clang 8.1.0 (clang-802.0.42)built with OpenSSL 1.1.0e  16 Feb 2017TLS SNI support enabledconfigure 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 -vnginx version: nginx/1.12.0$ $ nginx -hnginx version: nginx/1.12.0Usage: 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

123

$ nginx -tnginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is oknginx: 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
mac-os-x-install-nginx-02

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

nginx -s reload

nginx -s stop nginx

mac-os-x-install-nginx-03
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
install-software-mac-brew-01

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

例如wget,命令如下:

sudo brew install wget  

卸载命令如下:

sudo brew uninstall wget

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

sudo brew search /apache*/

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017年04月29日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档