brew install nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.6.2.yosemite.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/nginx-1.6.2.yosemite.bottle.1.tar.gz
==> Pouring nginx-1.6.2.yosemite.bottle.1.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.
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
==> Summary
/usr/local/Cellar/nginx/1.6.2: 7 files, 920K
默认根目录 /usr/local/var/www
默认配置文件 /usr/local/etc/nginx/nginx.conf
➜ ~ brew upgrade nginx
==> Upgrading 1 outdated package, with result:
nginx 1.8.0
==> Upgrading nginx
==> Installing dependencies for nginx: pcre, openssl
==> Installing nginx dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.38.el_capitan.bottle
######################################################################## 100.0%
==> Pouring pcre-8.38.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/pcre/8.38: 146 files, 5.4M
==> Installing nginx dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2e_1.el_capitan
######################################################################## 100.0%
==> Pouring openssl-1.0.2e_1.el_capitan.bottle.tar.gz
==> 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/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local.
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
==> Summary
🍺 /usr/local/Cellar/openssl/1.0.2e_1: 465 files, 11.9M
==> Installing nginx
==> Downloading https://homebrew.bintray.com/bottles/nginx-1.8.0.el_capitan.bott
######################################################################## 100.0%
==> Pouring nginx-1.8.0.el_capitan.bottle.1.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 reload nginx after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
nginx
==> Summary
🍺 /usr/local/Cellar/nginx/1.8.0: 7 files, 940.1K
启动nginx
sudo nginx
重新加载配置|重启|停止|退出 nginx
nginx -s reload|reopen|stop|quit
测试配置是否有语法错误
sudo 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
cd /usr/local/etc/nginx/
mkdir conf.d
vim nginx.conf
主要修改位置是最后增加一行include
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /usr/local/etc/nginx/conf.d/*.conf;
}
配置虚拟主机映射
在/etc/hosts文件中添加下面两行
127.0.0.1 www.bga.cn
127.0.0.1 bbs.bga.cn
vim /usr/local/etc/nginx/conf.d/bbs_bga.conf
server {
listen 80;
server_name bbs.bga.cn;
root /Users/bingoogol/NginxSite/bbs;
location / {
index index.php;
autoindex on;
}
#proxy the php scripts to php-fpm
location ~ .php$ {
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}
vim /usr/local/etc/nginx/conf.d/bbs_bga.conf
server {
listen 80;
server_name www.bga.cn;
root /Users/bingoogol/NginxSite/www;
location / {
index index.php;
autoindex on;
}
#proxy the php scripts to php-fpm
location ~ .php$ {
include /usr/local/etc/nginx/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
}
}
用brew安装php55和php-fpm
brew install php55 --with-fpm
替换php版本
vim .bash_profile
export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
就用刚刚安装的php代替了系统默认cli的php版本。然后在/etc/apache2/httpd.conf下增加
LoadModule php5_module /usr/local/Cellar/php55/php版本号/libexec/apache2/libphp5.so
这样就对apache使用的php版本也进行了修改。