首先安装Homebrew
查看nginx信息
brew info nginx
详细信息如下
nginx: stable 1.4.7 (bottled), devel 1.5.12, HEAD
http://nginx.org/
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/nginx.rb
==> Dependencies
Required: pcre ✘, openssl ✘
Optional: passenger ✘
==> Options
--with-debug
Compile with support for debug log
--with-gunzip
Compile with support for gunzip module
--with-passenger
Compile with support for Phusion Passenger module
--with-spdy
Compile with support for SPDY module
--with-webdav
Compile with support for WebDAV module
--devel
install development version 1.5.12
--HEAD
install HEAD version
==> 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.
To have launchd start nginx at login:
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
nginx
安装nginx
brew install nginx
配置nginx开机启动
ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
nginx配置文件路径
/usr/local/etc/nginx/nginx.conf
nginx常用操作
直接启动
nginx
修改配置后,验证配置文件语法
nginx -t
nginx运行时直接重启
nginx -s reload
nginx 启动异常
执行重启命令 nginx -s reload ,出现如下错误
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
原因是当前nginx还未启动,先执行 nginx,之后可以执行重启命令
测试安装启动成功
浏览器访问 http://localhost:8080/ 可以看到nginx的欢迎页