Nginx基于Ubuntu的源碼安裝

Nginx 基于Ubuntu的源碼安裝詳解

Nginx介紹


? ? ?Nginx?是一個高性能的HTTP反向代理服務(wù)器,也是一個IMAP/POP3/SMTP服務(wù)器。Nginx是由伊戈爾·賽索耶夫為俄羅斯訪問量第二的Rambler.ru站點(俄文:Рамблер)開發(fā)的,第一個公開版本0.1.0發(fā)布于2004年10月4日。Nginx是一款輕量級Web?服務(wù)器/反向代理服務(wù)器及電子郵件(IMAP/POP3)代理服務(wù)器,并在一個BSD-like 協(xié)議下發(fā)行。其特點是占有內(nèi)存少,并發(fā)能力強,事實上nginx的并發(fā)能力確實在同類型的網(wǎng)頁服務(wù)器中表現(xiàn)較好,中國大陸使用nginx網(wǎng)站用戶有:百度、京東、新浪網(wǎng)易、騰訊淘寶等。


Nginx 的安裝

Nginx 安裝之前需要三個依賴的支持

? ? Nginx模塊依賴性:

? ? ? ? ① gzip 模塊需要 zlib 庫?

? ? ? ? ② rewrite 模塊需要 pcre 庫?

? ? ? ? ③ ssl 功能需要 openssl 庫?

1. pcre庫安裝 ,該庫提供了正則表達式的支持。

$ wge ?http://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz

$ tar ?-zxf ? pcre-8.42.tar.gz

$ cd pcre-8.42

$ ./configure

$ make

$ sudo ?make ?install

2.?zlib庫安裝,Gzip模塊需要這個庫來做headers壓縮。

$ wget ?http://zlib.net/zlib-1.2.11.tar.gz

$ tar ?-zxf ? zlib-1.2.11.tar.gz

$ cd zlib-1.2.11

$ ./configure

$ make

$ sudo ?make ? install

3.?openssl庫,nginx ssl模塊需要這個庫來支持https協(xié)議。

$ ?wget http://www.openssl.org/source/openssl-1.0.2f.tar.gz

$ ?tar -zxf openssl-1.0.2f.tar.gz

$ ?cd openssl-1.0.2f

$ ./configure darwin64-x86_64-cc --prefix=/usr/local/openssl

$ make

$ sudo make install

4.下載Nginx源碼包,并進行解壓、安裝。

?$ ?wget ? http://nginx.org/download/nginx-1.12.0.tar.gz ? ?

$ ?tar ? ? zxf ? ?nginx-1.12.0.tar.gz ??

$ ? cd ? nginx-1.12.0 ? ?

$ ?./configure ? ?--prefix=/usr/local/nginx2 ? ?--with-pcre ? --with-http_stub_status_module ? ?--with-http_ssl_module ? ? --with-http_gzip_static_module ? ?--with-http_realip_module ? --add-module=/usr/local/nginx2/nginx_upstream_check_module-master ? ?--with-pcre=/usr/local/pcre/pcre-8.42 --with-zlib=/usr/local/zlib/zlib-1.2.11 --with-openssl=/usr/local/openssl/openssl-1.0.2f ??

$ ?make ??

$ ?make ? install

5. 其他選項指定方式

--error-log-path=path  默認是prefix/logs/error.log

--http-log-path=path   默認是prefix/logs/access.log

--user=user  ? ? ? ? ? 默認是nobody,表示由哪個用戶運行nginx worker thread

--group=group  ? ? ? ? 組名經(jīng)常設(shè)置為一個沒有權(quán)限的用戶名

--with-pcre-jit  ? ? ? 構(gòu)建pcre庫時,同時帶上"just-in-time compilation"的功能,這樣就能在配置文件中使用pcre_jit指令了

指定nginx的構(gòu)建選項,同時還可以指定編譯器的選項:

--with-cc-opt=parameters   添加額外的參數(shù)到CFLAGS 變量中

  在FreeBSD下,如果使用的是系統(tǒng)自帶的pcre庫,那么編譯時必須添加:--with-cc-opt="-I /usr/local/include";

  如果需要增加select()方法支持的文件數(shù)量,可以添加:--with-cc-opt="-D FD_SETSIZE=2048";

--with-ld-opt=parameters  ? 添加linking時需要的額外參數(shù)

  在FreeBSD下,如果使用的是系統(tǒng)自帶的pcre庫,那么編譯時必須添加:--with-ld-opt="-L /usr/local/lib";

6.?nginx的模塊選擇

? ? ?模塊可以靜態(tài)鏈接到nginx的二進制程序中,這樣當(dāng)nginx啟動的時候,就會加載它們;使用--add-module選項;

? ? ?模塊可以動態(tài)鏈接到nginx的二進制程序中,這樣只有在配置文件中指定這個模塊時,nginx才會去加載它們,使用--add-dynamic-module選項;

Nginx 的基本操作

?1. Nginx版本以及配置查看

root@ubuntu:/usr/local/nginx2/sbin# ./nginx -V

nginx version: nginx/1.12.0

built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10)

built with OpenSSL 1.0.1c 10 May 2012

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx2 --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --add-module=/usr/local/nginx2/nginx_upstream_check_module-master --with-pcre=/usr/local/pcre/pcre-8.42 --with-zlib=/usr/local/zlib/zlib-1.2.11 --with-openssl=/usr/local/openssl/openssl-1.0.1c-arm

root@ubuntu:/usr/local/nginx2/sbin# ./configure --prefix=/usr/local/nginx2 --with-pcre --with-http_stub_status_module --with-http_ssl_module? --with-http_gzip_static_module --with-http_realip_module --add-module=/usr/local/nginx2/nginx_upstream_check_module-master --with-pcre=/usr/local/pcre/pcre-8.42? --with-zlib=/usr/local/zlib/zlib-1.2.11? --with-openssl=/usr/local/openssl/openssl-1.0.1c-arm

2.?啟動關(guān)閉nginx

*檢查配置文件是否正確

/usr/local/nginx-1.6/sbin/nginx -t ??conf/nginx.conf

*啟動、關(guān)閉

./sbin/nginx # 默認配置文件 conf/nginx.conf,-c 指定

?./sbin/nginx -s stop 或 pkill nginx

*重啟,不會改變啟動時指定的配置文件

?./sbin/nginx -s reload 或 kill -HUP `cat /usr/local/nginx-1.6/logs/nginx.pid`

3.?確認nginx已經(jīng)起來并且運行正常

$ curl -I127.0.0.1

HTTP/1.1200 OK

Server: nginx/1.11.9


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容