http://www.cnblogs.com/badboyf/p/6422547.html
http://www.cnblogs.com/piscesLoveCc/p/5794926.html
1.gcc、g++依賴庫(kù)
apt-get install build-essential
apt-get install libtool
2.安裝 pcre依賴庫(kù)(http://www.pcre.org/)
sudo apt-get install libpcre3 libpcre3-dev或使用下面源碼安裝(推薦,后續(xù)需要源碼路徑)
*********
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz(注意版本號(hào)會(huì)更新)
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure
make
make install
**************
3.安裝 zlib依賴庫(kù)(http://www.zlib.net)
apt-get install zlib1g-dev
******************************
或源碼安裝(同上,推薦)
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz(同注意版本號(hào)會(huì)更新)
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
****************************
4.安裝ssl依賴庫(kù)(ubuntu16.04 LTS 已經(jīng)安裝過(guò)了)
apt-get install openssl
***************************
(后面需要路徑,可通過(guò)which查看)
which openssl
得到/usr/bin/openssl
************************************
5.安裝nginx
cd /usr/local/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.40 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/bin/openssl
make
make install
***********************************************
下面是對(duì)上面的參數(shù)的一些說(shuō)明:
--prefix=path定義一個(gè)目錄,存放服務(wù)器上的文件 ,也就是nginx的安裝目錄。默認(rèn)使用/usr/local/nginx。
--sbin-path=path設(shè)置nginx的可執(zhí)行文件的路徑,默認(rèn)為prefix/sbin/nginx.
--conf-path=path設(shè)置在nginx.conf配置文件的路徑。nginx允許使用不同的配置文件啟動(dòng),通過(guò)命令行中的-c選項(xiàng)。默認(rèn)為prefix/conf/nginx.conf.
--pid-path=path設(shè)置nginx.pid文件,將存儲(chǔ)的主進(jìn)程的進(jìn)程號(hào)。安裝完成后,可以隨時(shí)改變的文件名 , 在nginx.conf配置文件中使用 PID指令。默認(rèn)情況下,文件名 為prefix/logs/nginx.pid.
--error-log-path=path設(shè)置主錯(cuò)誤,警告,和診斷文件的名稱。安裝完成后,可以隨時(shí)改變的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默認(rèn)情況下,文件名 為prefix/logs/error.log.
--http-log-path=path設(shè)置主請(qǐng)求的HTTP服務(wù)器的日志文件的名稱。安裝完成后,可以隨時(shí)改變的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默認(rèn)情況下,文件名 為prefix/logs/access.log.
--user=name設(shè)置nginx工作進(jìn)程的用戶。安裝完成后,可以隨時(shí)更改的名稱在nginx.conf配置文件中 使用的 user指令。默認(rèn)的用戶名是nobody。
--group=name設(shè)置nginx工作進(jìn)程的用戶組。安裝完成后,可以隨時(shí)更改的名稱在nginx.conf配置文件中 使用的 user指令。默認(rèn)的為非特權(quán)用戶。
--with-select_module--without-select_module?啟用或禁用構(gòu)建一個(gè)模塊來(lái)允許服務(wù)器使用select()方法。該模塊將自動(dòng)建立,如果平臺(tái)不支持的kqueue,epoll,rtsig或/dev/poll。
--with-poll_module--without-poll_module啟用或禁用構(gòu)建一個(gè)模塊來(lái)允許服務(wù)器使用poll()方法。該模塊將自動(dòng)建立,如果平臺(tái)不支持的kqueue,epoll,rtsig或/dev/poll。
--without-http_gzip_module— 不編譯壓縮的HTTP服務(wù)器的響應(yīng)模塊。編譯并運(yùn)行此模塊需要zlib庫(kù)。
--without-http_rewrite_module不編譯重寫模塊。編譯并運(yùn)行此模塊需要PCRE庫(kù)支持。
--without-http_proxy_module— 不編譯http_proxy模塊。
--with-http_ssl_module— 使用https協(xié)議模塊。默認(rèn)情況下,該模塊沒(méi)有被構(gòu)建。建立并運(yùn)行此模塊的OpenSSL庫(kù)是必需的。
--with-pcre=path—?設(shè)置PCRE庫(kù)的源碼路徑。PCRE庫(kù)的源碼(版本4.4 - 8.30)需要從PCRE網(wǎng)站下載并解壓。其余的工作是Nginx的./ configure和make來(lái)完成。正則表達(dá)式使用在location指令和 ngx_http_rewrite_module 模塊中。
--with-pcre-jit—編譯PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。
--with-zlib=path—設(shè)置的zlib庫(kù)的源碼路徑。要下載從 zlib(版本1.1.3 - 1.2.5)的并解壓。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模塊需要使用zlib 。
--with-cc-opt=parameters— 設(shè)置額外的參數(shù)將被添加到CFLAGS變量。例如,當(dāng)你在FreeBSD上使用PCRE庫(kù)時(shí)需要使用:--with-cc-opt="-I /usr/local/include。.如需要需要增加select()支持的文件數(shù)量:--with-cc-opt="-D FD_SETSIZE=2048".
--with-ld-opt=parameters—設(shè)置附加的參數(shù),將用于在鏈接期間。例如,當(dāng)在FreeBSD下使用該系統(tǒng)的PCRE庫(kù),應(yīng)指定:--with-ld-opt="-L /usr/local/lib".
啟動(dòng)nginx服務(wù)
/usr/local/nginx/sbin/nginx
停止服務(wù)
/usr/local/nginx/sbin/nginx -s stop