ubuntu 下 升级 nginx

来源:互联网 发布:老年机数据流量开关 编辑:程序博客网 时间:2024/05/14 08:17

我的是一开始用 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 重启 一边


0 0
原创粉丝点击