很早就聽聞nginx的大名,輕量級高併發的特性一直吸引着我,但一直沒有時間顧及,最近因爲各類緣由,準備學習一下nginx這個神器。好的,讓咱們進入正題。今天先來安裝一下。 nginx
首先我用的是蘋果最新的 Mac OS X Mavericks 10.9的系統,因此準備採用源碼編譯的方法來安裝。
bash
能夠在這裏下載最新版,我這裏使用的是8.33的版本而後在終端執行下面的命令。 併發
cd ~/Download tar xvzf pcre-8.33.tar.gz cd pcre-8.12 sudo ./configure --prefix=/usr/local sudo make sudo make install
首先在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 # 默認編譯參數對應的安裝路徑(*_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"
爲了方便: spa
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
或者直接在編譯時設定 code
./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
編譯參數參考 Nginx InstallOption md5
檢查PATH環境變量 get
# ~/.bash_profile export PATH=/usr/local/bin:/usr/local/sbin:$PATH
啓動Nginx 源碼
sudo nginx
須要中止Nginx的時候運行
sudo nginx -s stop
建立文件 /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