Mac环境Nginx的搭建以及使用

Mac环境Nginx安装及使用教程

1.简介

Nginx(“engine x”)是一款开源的web和反向代理服务。具有高性能、高并发、低内存特点,另外还有一些特色的Web服务器功能,如负载均衡、缓存、访问和带宽控制。

MAC环境下有一个好用的软件安装方法,使用homebrew来安装各个软件既快捷又不用考虑依赖包的问题。

2.安装

2.1 先安装homebrew。终端执行以下命令

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

出现以下log表示安装完成了。

Installation successful!

2.2 安装Nginx,终端下执行

brew install nginx

 

安装过程中会自己安装依赖:

$ brew install nginx

Warning: You have Xcode 8 installed without the CLT;

this causes certain builds to fail on OS X El Capitan (10.11).

Please install the CLT via:

  sudo xcode-select --install

==> Installing dependencies for nginx: openssl, pcre

==> Installing nginx dependency: openssl

安装完成后会有以下log

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

2.3鉴于安装过程中出现的Warning,为避免将来掉坑,运行

sudo xcode-select --install

终端会出现提示

xcode-select: note: install requested for command line developer tools

并会询问安装工具

 

xcode-select

点击安装,等待软件安装完成即可。

2.4 启动nginx服务

brew services start nginx

$ brew services start nginx

==> Tapping homebrew/services

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...

remote: Counting objects: 10, done.

remote: Compressing objects: 100% (7/7), done.

remote: Total 10 (delta 0), reused 6 (delta 0), pack-reused 0

Unpacking objects: 100% (10/10), done.

Checking connectivity... done.

Tapped 0 formulae (36 files, 46.1K)

==> Successfully started `nginx` (label: homebrew.mxcl.nginx)

成功后,使用浏览器打开http://localhost:8080 

如果打开页面如下,证明安装完成,可以使用了。

 

screenshot200.png

3. nginx默认文件目录

3.1  nginx安装文件目录
/usr/local/Cellar/nginx

3.2  nginx配置文件目录
/usr/local/etc/nginx

3.3 config文件目录
/usr/local/etc/nginx/nginx.conf

3.4 系统hosts位置
/private/etc/hosts


4. nginx常用命令

nginx  #启动nginx

nginx -s quit  #快速停止nginx

nginx -V #查看版本,以及配置文件地址

nginx -v #查看版本

nginx -s reload|reopen|stop|quit   #重新加载配置|重启|快速停止|安全关闭nginx

nginx -h #帮助

$ nginx -h #帮助

nginx version: nginx/1.10.1

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.10.1/)

  -c filename   : set configuration file (default: /usr/local/etc/nginx/nginx.conf)

  -g directives : set global directives out of configuration file

5. 卸载nginx

brew uninstall nginx

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值