很早就聽聞nginx的大名,輕量級高并發(fā)的特性一直吸引著我,但一直沒有時間顧及,最近由于各種原因,準備學習一下nginx這個神器。好的,讓我們進入正題。今天先來安裝一下。
首先我用的是蘋果最新的 Mac OS X Mavericks 10.9的系統(tǒng),所以準備采用源碼編譯的方法來安裝。
1.先安裝PCRE庫
可以在這里下載最新版,我這里使用的是8.33的版本然后在終端執(zhí)行下面的命令。
cd ~/Download tar xvzf pcre-8.33.tar.gz cd pcre-8.12 sudo ./configure --prefix=/usr/local sudo make sudo make install
2.下載安裝nginx
首先在nginx官網下載最新的源碼,我這里用的是nginx-1.5.2
tar -zvxf nginx-1.5.2.tar.gz cd nginx-1.5.2 ./configure
默認編譯概要:
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 # 默認編譯參數(shù)對應的安裝路徑(*_temp 為目錄) 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"
為了方便:
sudo ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx sudo ln -s /usr/local/nginx/conf /etc/nginx sudo ln -s /usr/local/nginx/logs/nginx.pid /var/run/nginx.pid sudo ln -s /usr/local/nginx/logs /var/log/nginx
或者直接在編譯時設定
./configure \ --prefix=/usr/local \ --sbin-path=/usr/local/sbin \ --conf-path=/etc/nginx \ --pid-path=/var/run \ --error-log-path=/var/log/nginx \ --http-log-path=/var/log/nginx
編譯參數(shù)參考 Nginx InstallOption
3.啟動Nginx
檢查PATH環(huán)境變量
# ~/.bash_profile export PATH=/usr/local/bin:/usr/local/sbin:$PATH
啟動Nginx
sudo nginx
需要停止Nginx的時候運行
sudo nginx -s stop
4.配置自啟動
創(chuàng)建文件 /System/Library/LaunchDaemons/nginx.plist
Labelnginx Program/usr/local/sbin/nginx KeepAlive NetworkState StandardErrorPath/var/log/system.log LaunchOnlyOnce
載入自啟動文件
launchctl load -F /System/Library/LaunchDaemons/nginx.plist