1.安裝gcc g++的依賴庫html
apt-get install build-essential
apt-get install libtool
2.安裝pcre依賴庫nginx
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
3.安裝zlib依賴庫正則表達式
sudo apt-get install zlib1g-dev
4.安裝ssl依賴庫ubuntu
apt-get install openssl
5.安裝Nginx服務器
#下載最新版本:
wget http://nginx.org/download/nginx-1.11.3.tar.gz
#解壓:
tar -zxvf nginx-1.11.3.tar.gz
#進入解壓目錄:
cd nginx-1.11.3
#配置:
./configure --prefix=/usr/local/nginx
#編輯nginx:
make
注意:這裏可能會報錯,提示「pcre.h No such file or directory」,具體詳見:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory
須要安裝 libpcre3-dev,命令爲:sudo apt-get install libpcre3-dev
#安裝nginx:
sudo make install
#啓動nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路徑,不加的話,nginx會自動加載默認路徑的配置文件,能夠經過 -h查看幫助命令。
#查看nginx進程:
ps -ef|grep nginx
./configure 參數含義:
--prefix=path 定義一個目錄,存放服務器上的文件 ,也就是nginx的安裝目錄。默認使用 /usr/local/nginx。
--sbin-path=path 設置nginx的可執行文件的路徑,默認爲 prefix/sbin/nginx.
--conf-path=path 設置在nginx.conf配置文件的路徑。nginx容許使用不一樣的配置文件啓動,經過命令行中的-c選項。默認爲prefix/conf/nginx.conf.
--pid-path=path 設置nginx.pid文件,將存儲的主進程的進程號。安裝完成後,能夠隨時改變的文件名 , 在nginx.conf配置文件中使用 PID指令。默認狀況下,文件名 爲prefix/logs/nginx.pid.
--error-log-path=path 設置主錯誤,警告,和診斷文件的名稱。安裝完成後,能夠隨時改變的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默認狀況下,文件名 爲prefix/logs/error.log.
--http-log-path=path 設置主請求的HTTP服務器的日誌文件的名稱。安裝完成後,能夠隨時改變的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默認狀況下,文件名 爲prefix/logs/access.log.
--user=name 設置nginx工做進程的用戶。安裝完成後,能夠隨時更改的名稱在nginx.conf配置文件中 使用的 user指令。默認的用戶名是nobody。
--group=name 設置nginx工做進程的用戶組。安裝完成後,能夠隨時更改的名稱在nginx.conf配置文件中 使用的 user指令。默認的爲非特權用戶。
--with-select_module--without-select_module 啓用或禁用構建一個模塊來容許服務器使用select()方法。該模塊將自動創建,若是平臺不支持的kqueue,epoll,rtsig或/dev/poll。
--with-poll_module--without-poll_module 啓用或禁用構建一個模塊來容許服務器使用poll()方法。該模塊將自動創建,若是平臺不支持的kqueue,epoll,rtsig或/dev/poll。
--without-http_gzip_module — 不編譯壓縮的HTTP服務器的響應模塊。編譯並運行此模塊須要zlib庫。
--without-http_rewrite_module 不編譯重寫模塊。編譯並運行此模塊須要PCRE庫支持。
--without-http_proxy_module — 不編譯http_proxy模塊。
--with-http_ssl_module — 使用https協議模塊。默認狀況下,該模塊沒有被構建。創建並運行此模塊的OpenSSL庫是必需的。
--with-pcre=path — 設置PCRE庫的源碼路徑。PCRE庫的源碼(版本4.4 - 8.30)須要從PCRE網站下載並解壓。其他的工做是Nginx的./ configure和make來完成。正則表達式使用在location指令和 ngx_http_rewrite_module 模塊中。
--with-pcre-jit —編譯PCRE包含「just-in-time compilation」(1.1.12中, pcre_jit指令)。
--with-zlib=path —設置的zlib庫的源碼路徑。要下載從 zlib(版本1.1.3 - 1.2.5)的並解壓。其他的工做是Nginx的./ configure和make完成。ngx_http_gzip_module模塊須要使用zlib 。
--with-cc-opt=parameters — 設置額外的參數將被添加到CFLAGS變量。例如,當你在FreeBSD上使用PCRE庫時須要使用:--with-cc-opt="-I /usr/local/include。.如須要須要增長 select()支持的文件數量:--with-cc-opt="-D FD_SETSIZE=2048".
--with-ld-opt=parameters —設置附加的參數,將用於在連接期間。例如,當在FreeBSD下使用該系統的PCRE庫,應指定:--with-ld-opt="-L /usr/local/lib".
1.啓動Nginx測試
/usr/local/nginx/sbin/nginx
./sbin/nginx
2.中止Nginx網站
./sbin/nginx -s stop
./sbin/nginx -s quit
3.Nginx從新加載配置ui
./sbin/nginx -s reload
4.指定配置文件spa
./sbin/nginx -c /usr/local/nginx/conf/nginx.conf
5.查看Nginx版本命令行
1.顯示版本(小寫v)
./sbin/nginx -v
nginx: nginx version: nginx/1.0.0
2.顯示詳細信息(大寫)
./sbin/nginx -V
nginx version: nginx/1.11.3
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
built with OpenSSL 1.0.2g 1 Mar 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module
6.檢查文件是否正確
poerchant@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
7.顯示幫助信息
./sbin/nginx -h
如下是從新編譯的代碼和模塊
./configure --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
make 千萬別make install,不然就覆蓋安裝了
make完以後在objs目錄下就多了個nginx,這個就是新版本的程序了
備份舊的nginx程序
cp /usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx.bak
把新的nginx程序覆蓋舊的
cp objs/nginx /usr/local/nginx/sbin/nginx
測試新的nginx程序是否正確
/usr/local/nginx/sbin/nginx -t
nginx: theconfiguration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/nginx/conf/nginx.conf test issuccessful
平滑重啓nginx
/usr/local/nginx/sbin/nginx -s reload