1. 程式人生 > >ubuntu 下 升級 nginx

ubuntu 下 升級 nginx

我的是一開始用 apt-get install nginx 安裝的,所以下面是 在已經安裝的情況下升級

下載 stable版本的nginx :

    http://nginx.org/en/download.html 這裡 我下載的 1.6.2 stable 版本

進入到要儲存檔案的目錄 我的是 cd /home

   wget  http://nginx.org/download/nginx-1.6.2.tar.gz

然後 解壓 檔案

    tar -zxvf nginx-1.6.2.tar.gz

使用 nginx -V 檢視自己的引數(V是大寫):

比如我的是:


進去到你下載並解壓好的資料夾下,比如我解壓的檔案在 /home/nginx-1.6.2 :

cd /home/nginx-1.6.2

執行 ./configure 後面跟上你的 --prefix 比如 我的:

 --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module

回車:

可能會出現問題 因為你一開始的 nginx不是編譯的 ,可能出現以下一些問題(我出現的問題,如果和我的不一樣 去google):

安裝libxslt

./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries.

apt-get install libxslt1-dev(注意這裡的 可能和你的不一樣 當你打 libxslt 時  按tab 看會出現什麼 東西 因為軟體可能和你的不一樣) 
缺少GD library

./configure: error: the HTTP image filter module requires the GD library.

apt-get install libgd2-xpm libgd2-xpm-dev 和上面的 一樣 按 tab 看給你什麼東西

以下的 可能你會遇到:

rewrite需要pcre支援
./configure: error: the HTTP rewrite module requires the PCRE library.

apt-get install libpcre3 libpcre3-dev  和上面的 一樣 按 tab 看給你什麼東西

http cache需要openssl
./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.

apt-get install libssl-dev openssl  和上面的 一樣 按 tab 看給你什麼東西

 安裝GeoIP library
./configure: error: the GeoIP module requires the GeoIP library.

apt-get install libgeoip-dev  和上面的 一樣 按 tab 看給你什麼東西

在 執行 ./configure --prefix ......  //這裡是你的 引數不要複製過去

好了後會看到 這個 :

然後執行 make,等待結束

用 which nginx 檢視你的 nginx 啟動程式在哪 我的在 /usr/sbin/nginx 

備份舊版本的nginx可執行檔案

mv  /usr/sbin/nginx    /usr/sbin/nginx.old

複製新版本的nginx這行檔案

因為 前面你到了nginx-1.6.2資料夾下 用 ls  檢視 會發現有個 objs 目錄

cp  objs/nginx   /usr/sbin/

檢視  是否正確   :

nginx -t

如果出現這個 說明真確

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

執行 make upgrade (說明 可能你在別的地方看到 make install   如果是 升級 應該是 upgrade)

如果尼出現了錯誤那麼修改一下Makefile(ls 就能看到這個檔案)裡面的upgrade標籤下的路徑,修改為正確的Nginx可執行檔案的路徑,Ubuntu下一般是/usr/sbin/nginx (就是用which nginx 看到的 路徑 )這時 你會 看到 有clean  install 和 upgrade 等 我們 make upgrade  就是執行這個 upgrade  如果你在 其他 地方看到 最後執行

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid` 等 其他的 命令 這裡 你執行  make upgrade  就行 了因為裡面已經包含了你要的命令  這也是最後一步 

至此  已經升級完成  nginx -v (小v)檢視版本已經是 1.6.2 版本 如果 不放心 可以 service nginx  restart 重啟 一邊