Nginx安装升级

通常利用系统自带的源安装的nginx 版本比较低,在进行漏洞扫描时候会有很多漏洞所以建议升级到最新版本。

本次就介绍从第一次安装到升级的简单操作。

如果是使用中的 一定要备份配置文件。如果是使用中的 一定要备份配置文件。如果是使用中的 一定要备份配置文件。

首先初次安装,我是centos7系统,初次安装直接yum就可以。

[root@az2-ccs-uat-main-01 /]# yum install -y nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * epel: mirrors.tuna.tsinghua.edu.cn

此处省略N个字........................

Installed:
  nginx.x86_64 1:1.12.2-2.el7                                                                                                                                                                

Dependency Installed:
  dejavu-fonts-common.noarch 0:2.33-6.el7     dejavu-sans-fonts.noarch 0:2.33-6.el7              fontconfig.x86_64 0:2.13.0-4.3.el7         fontpackages-filesystem.noarch 0:1.44-8.el7      
  gd.x86_64 0:2.0.35-26.el7                   gperftools-libs.x86_64 0:2.6.1-1.el7               libX11.x86_64 0:1.6.5-2.el7                libX11-common.noarch 0:1.6.5-2.el7               
  libXau.x86_64 0:1.0.8-2.1.el7               libXpm.x86_64 0:3.5.12-1.el7                       libjpeg-turbo.x86_64 0:1.2.90-6.el7        libpng.x86_64 2:1.5.13-7.el7_2                   
  libxcb.x86_64 0:1.13-1.el7                  libxslt.x86_64 0:1.1.28-5.el7                      nginx-all-modules.noarch 1:1.12.2-2.el7    nginx-filesystem.noarch 1:1.12.2-2.el7           
  nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7  nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7  nginx-mod-http-perl.x86_64 1:1.12.2-2.el7  nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 
  nginx-mod-mail.x86_64 1:1.12.2-2.el7        nginx-mod-stream.x86_64 1:1.12.2-2.el7            

Dependency Updated:
  freetype.x86_64 0:2.8-12.el7_6.1                                                                                                                                                           

Complete!
[root@az2-ccs-uat-main-01 /]# nginx -v
nginx version: nginx/1.12.2

安装完了查看版本发现是1.12.2,配置文件默认位置在/etc/nginx/下而目前Nginx官网最新版本是1.15,现在进行升级

先去Nginx官网找到你需要升级的包,下载到服务器。

[root@az2-ccs-uat-main-01 /]# wget http://nginx.org/download/nginx-1.15.9.tar.gz
--2019-03-01 11:13:00--  http://nginx.org/download/nginx-1.15.9.tar.gz
Resolving nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|62.210.92.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1031760 (1008K) [application/octet-stream]
Saving to: ‘nginx-1.15.9.tar.gz’

100%[===================================================================================================================================================>] 1,031,760   24.8KB/s   in 29s    

2019-03-01 11:13:30 (35.2 KB/s) - ‘nginx-1.15.9.tar.gz’ saved [1031760/1031760]
[root@az2-ccs-uat-main-01 /]# tar -zxvf nginx-1.15.9.tar.gz 
nginx-1.15.9/
nginx-1.15.9/auto/
nginx-1.15.9/conf/
....
[root@az2-ccs-uat-main-01 /]# cd /nginx-1.15.9
[root@az2-ccs-uat-main-01 nginx-1.15.9]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@az2-ccs-uat-main-01 nginx-1.15.9]#

下载完了解压 进入解压后的目录。

然后查一下当前nginx安装的模块信息,如果你了解自己需要什么模块那可以自己指定。

[root@az2-ccs-uat-main-01 nginx-1.15.9]# nginx -V   此处是大写的V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
[root@az2-ccs-uat-main-01 nginx-1.15.9]# 

根据查出的模块选择你想用的模块进行安装,如果不清楚需要用哪个那就把查询出来的全部复制。

执行安装

###
[root@az2-ccs-uat-main-01 nginx-1.15.9]# ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
checking for OS
 + Linux 3.10.0-862.14.4.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
checking for gcc -pipe switch ... found
checking for --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E" ... not found
./configure: error: the invalid value in --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"


####此处报错 说明这个模块的参数错误,我们可以在编译信息中去掉这个模块。然后再次编译。

[root@az2-ccs-uat-main-01 nginx-1.15.9]# ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic'
checking for OS
 + Linux 3.10.0-862.14.4.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... not found
checking for gcc builtin atomic operations ... not found
checking for C99 variadic macros ... not found
checking for gcc variadic macros ... not found
...............................................

./configure: no supported file AIO was found
Currently file AIO is supported on FreeBSD 4.3+ and Linux 2.6.22+ only
###路径不对或者没有找到AIO这个模块,同上,再编译参数中去掉。

[root@az2-ccs-uat-main-01 nginx-1.15.9]# ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic'
checking for OS
 + Linux 3.10.0-862.14.4.el7.x86_64 x86_64
checking for C compiler ... found
...........................
checking for int size ...
./configure: error: can not detect int size
###这是说CPU优化模块或者配置参数有问题。没有强迫症去掉有关优化的模块就可以了就可以了。
再次执行
##报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
###这个是说某些依赖库没有安装。
###下面进行安装
[root@az2-ccs-uat-main-01 nginx-1.15.9]# yum -y install pcre-devel openssl openssl-devel

###报错
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.
解决方法:
[root@az2-ccs-uat-main-01 nginx-1.15.9]# yum -y install libxslt-devel libxml2

###报错
./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.
###http_image_filter_module是nginx提供的集成图片处理模块,需要gd-devel的支持
解决方法:
[root@az2-ccs-uat-main-01 nginx-1.15.9]# yum -y install gd-devel
###报错
./configure: error: perl module ExtUtils::Embed is required
###缺少ExtUtils
解决方法:
[root@az2-ccs-uat-main-01 nginx-1.15.9]# yum -y install perl-devel perl-ExtUtils-Embed
###报错
./configure: error: the GeoIP module requires the GeoIP library.
You can either do not enable the module or install the library.
缺少GeoIP
解决方法:
[root@az2-ccs-uat-main-01 nginx-1.15.9]# yum -y install GeoIP GeoIP-devel GeoIP-data


nginx编译成功回显其目录结构:类似下面这种:
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/share/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/usr/lib64/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/lib/nginx/tmp/client_body"
  nginx http proxy temporary files: "/var/lib/nginx/tmp/proxy"
  nginx http fastcgi temporary files: "/var/lib/nginx/tmp/fastcgi"
  nginx http uwsgi temporary files: "/var/lib/nginx/tmp/uwsgi"
  nginx http scgi temporary files: "/var/lib/nginx/tmp/scgi"

./configure: warning: the "--with-ipv6" option is deprecated   ###此处为提醒
[root@az2-ccs-uat-main-01 nginx-1.15.9]# 
最后执行安装
[root@az2-ccs-uat-main-01 nginx-1.15.9]# make && make install
安装完成 

最后查看版本信息

[root@az2-ccs-uat-main-01 nginx-1.15.9]# nginx -v
nginx version: nginx/1.15.9
[root@az2-ccs-uat-main-01 nginx-1.15.9]#

全部搞定!

 

打赏

30 Comments

  • Hi to all, the contents present at this site are really remarkable for people
    knowledge, well, keep up the good work fellows.

  • Thanks a bnch for sharing this with all people yyou really
    know what you are speaking about! Bookmarked. Kindly also
    consult with my web site =). We coluld have a link exchange agreement among us

  • It’s remarkable designed for me to have a web
    page, which is good for my knowledge. thanks admin

  • Thanks for sharing your thoughts on eco friendly toys.
    Regards

  • http://hasem.app

    كود خصم,كوبونات خصم,اكواد خصم,صحصح,صح صح,كوبون خصم,خصم نمشي,خصم نون,خصم مذركير,خصم ايهرب,خصم اي هرب,خصم اي هيرب,

  • After opening Video Creator Explaindio, you will
    note an exceptionally good interface.

  • Its not my first time to visit this website, i am browsing this web site dailly
    and get nice data from here daily.

  • Thanks for the good writeup. It if truth be told was once a amusement account it.
    Look complicated to more delivered agreeable from you!

    By the way, how could we keep up a correspondence?

  • I don’t know if it’s just me or if perhaps everyone else experiencing problems with your blog.
    It appears like some of the written text on your content are running off the screen.
    Can someone else please provide feedback and let me know
    if this is happening to them as well? This might be a issue with
    my browser because I’ve had this happen before. Cheers

  • sildeenafil online sildenafil Selfcare habits Inspite
    oof her era, the King continues to walk, and cruise horses daily!
    (I notice that your sweetheart needed to get yourself a shorter flrm of transport
    so it would be easier to mount)She never runs on the
    bannister regardless if she is in the heavy top or manteau because it creates her coreShe eats common and balanced meals.
    Our liberatesd soul now reflets the Ligt and Logic of Fin.

  • This is my first time go to see at here and i am genuinely
    impressed to read everthing at one place.

  • Pisarz bloga podążą ewidentnie nietuzinkową ścieżką.

  • I got this site from my pal who informed me about
    this web site and now this time I am visiting this site and reading very informative posts at this
    place.

  • Blogger – wejdź dzięki i postępuj według instrukcją.

  • For most up-to-date news you have to go to see world wide web and on internet I found this site as
    a best web page for most up-to-date updates.

  • Magnificent goods from you, man. I’ve understand your stuff previous
    to and you are just too wonderful. I actually like what you’ve acquired here, certainly like what you’re saying
    and the way in which you say it. You make it enjoyable and you still care for
    to keep it smart. I cant wait to read far more from you.
    This is really a terrific site.

  • What’s up mates, how is the whole thing, and what you
    want to say regarding this article, in my view its actually remarkable in support of me.

  • skuteczne środki na odchudzanie szybkie odchudzanie tabletki Większe OW jest ściśle zespolone zze odmianami w spojrzeniu
    na wygląd, co wydaje się zgodne zręcznością filozofią buddyjską i literaturą dotyczącą
    uważności Hˆlzel et al. Są too zakłóca działalność perforiny a, także zapobiega
    obowiązującej odpowiedzi telefonów komórkowych odpornościowych
    dzięki najeźdźców. Czyli, jaak organizm i odczuwane doznania znajdują się wewnętrznie używane
    przez podmiot do regulowania stresu czy też uwagi jak i również
    jak podobne odczucia pozostają powiązane wraz ze stanem
    emocjonalnym człowieka w toku, w jakim ciało jet widziane jako
    stabilne lub dyskomfortowe, patrz też Mehling,.

  • Всем привет! Есть новые коды для
    букмекерки Betwinner! Таких нет на
    сайте БК, так как они – специальная акция от
    партнёров букмекера. Кому надо получить большие бонусы
    или фрибеты – копируйте и применяйте.
    Не пропустите – акция с бонускодами
    2020 для Бетвиннер действует прямо сейчас!

    https://betwinner-promocod.ru/

  • https://markenets.com

    بيع متابعين تويتر عرب,ارخص سيرفر بيع
    متابعين,شراء وبيع متابعين حقيقين,
    بيع متابعين تيك توك,بيع متابعين انسقرام,

  • Awesome! Its in fact awesome article, I have got much clear idea concerning from this
    piece of writing.

  • naturally like your web-site however you need to check the spelling on quite a few of your
    posts. A number of them are rife with spelling issues and I find it very bothersome to tell the
    truth on the other hand I will surely come back again.

  • Superb blog! Do you have any tips and hints for aspiring writers?
    I’m planning to start my own site soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress or go for a paid option?
    There are so many choices out there that I’m totally confused ..
    Any ideas? Thanks a lot!

  • This post provides clear idea in support of the new people
    of blogging, that truly how to do blogging and site-building.

  • What i do not understood is in fact how you are no longer really a lot more smartly-preferred than you
    may be now. You are so intelligent. You realize therefore significantly in the case of this matter, produced me individually believe it from so many various angles.
    Its like men and women aren’t involved unless it’s one thing to do with Lady gaga!
    Your own stuffs nice. Always care for it up!

  • There is never really strategy when it comes to playing slots,
    you’ve just got to be lucky 🙂 and only play
    when you enjoy it

  • Impressive stuff, keep up the good work.

  • Great concert !

  • Hello, the whole thing is going fine here and ofcourse every one is sharing information, that’s truly good,
    keep up writing.

Leave a Comment