Mac安装配置Nginx

1. 安装PCRE库(Nginx rewrite依赖PCRE库)

下载PCRE:  http://www.pcre.org

tar xvzf pcre-8.37.tar.gz
cd pcre-8.37
sudo ./configure --prefix=/usr/local
sudo make
sudo make install

2. 安装Nginx

下载Nginx:  http://nginx.org

tar xvzf nginx-1.8.0.tar.gz
cd nginx-1.8.0
sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-cc-opt="-Wno-deprecated-declarations"
sudo make
sudo make install

编译概要: 

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

  

3.  配置环境变量:

sudo vi ~/.bash_profile
# Append content to bash_proflie
export PATH=/usr/local/nginx/bin:/usr/local/nginx/sbin:$PATH
source ./bash_profile

 4. 配置Nginx开机启动:

cd /System/Library/LaunchDaemons
sudo touch nginx.plist
sudo vi nginx.plist 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>nginx</string>
  <key>KeepAlive</key>
  <true/>
  <key>Program</key>
  <string>/usr/local/bin/nginx</string>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>
 

 载入Nginx开机启动文件

launchctl load -w /System/Library/LaunchDaemons/nginx.plist
 

 5.  启动:

sudo nginx

 停止:

sudo nginx -s stop

 重启:

sudo nginx -s reload

相关推荐