源码编译安装nginx

2022-05-06 17:15:15 浏览数 (1)

源码编译安装基本步骤:

1、下载 2、解压源码包 3、准备编译环境 4、检查(依赖,兼容),预编译 5、编译 6、安装

所以nginx的源码编译安装也是基本的6步:

1、下载源码

     http://nginx.org/,单击download,下载最新的stable的源码

2、解压源码包

    [root@master ~]# tar -zxvf nginx-1.10.2.tar.gz

3、准备编译环境

   [root@master ~]# yum grouplist | grep Development    Additional Development    Desktop Platform Development    Development tools    Server Platform Development

  [root@master ~]# yum groupinstall -y Development Tools

4、检查(依赖,兼容),预编译

   [root@master nginx-1.10.2]# ls    auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src

4.1  查看帮助

  [root@master nginx-1.10.2]# ./configure --help     --help                                        print this message     --prefix=PATH                          set installation prefix     --sbin-path=PATH                   set nginx binary pathname

    ...................

4.2  预编译,设置安装路径

  [root@master nginx-1.10.2]# ./configure --prefix=/opt/nginx-1.10.2

  ...........

  checking for PCRE library in /usr/pkg/ ... not found   checking for PCRE library in /opt/local/ ... not found ./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.

4.3 安装依赖

  [root@master nginx-1.10.2]# yum search pcre   Loaded plugins: fastestmirror

  pcre-devel.i686 : Development files for pcre   pcre-devel.x86_64 : Development files for pcre   pcre-static.x86_64 : Static library for pcre   pcre.i686 : Perl-compatible regular expression library   pcre.x86_64 : Perl-compatible regular expression library

  [root@master nginx-1.10.2]# yum install -y pcre-devel

4.4 再次预编译,安装依赖  

  [root@master nginx-1.10.2]# ./configure --prefix=/opt/nginx-1.10.2

./configure: error: the HTTP gzip module requires the zlib library.   You can either disable the module by using --without-http_gzip_module   option, or install the zlib library into the system, or build the zlib library   statically from the source with nginx by using --with-zlib=<path> option.

  [root@master nginx-1.10.2]# yum search zlib

  jzlib.x86_64 : JZlib re-implementation of zlib in pure Java   jzlib-demo.x86_64 : Examples for jzlib   jzlib-javadoc.x86_64 : Javadoc for jzlib   perl-Compress-Raw-Zlib.x86_64 : Low-Level Interface to the zlib compression library   perl-Compress-Zlib.x86_64 : A module providing Perl interfaces to the zlib compression library   perl-IO-Zlib.x86_64 : Perl IO:: style interface to Compress::Zlib   zlib.i686 : The zlib compression and decompression library   zlib.x86_64 : The zlib compression and decompression library   zlib-devel.i686 : Header files and libraries for Zlib development   zlib-devel.x86_64 : Header files and libraries for Zlib development   zlib-static.x86_64 : Static libraries for Zlib development

  [root@master nginx-1.10.2]# yum install -y zlib-devel

4.5 重复执行预编译,直到没有错误

  [root@master nginx-1.10.2]# ./configure --prefix=/opt/nginx-1.10.2

  nginx path prefix: "/opt/nginx-1.10.2"   nginx binary file: "/opt/nginx-1.10.2/sbin/nginx"   nginx modules path: "/opt/nginx-1.10.2/modules"   nginx configuration prefix: "/opt/nginx-1.10.2/conf"   nginx configuration file: "/opt/nginx-1.10.2/conf/nginx.conf"   nginx pid file: "/opt/nginx-1.10.2/logs/nginx.pid"   nginx error log file: "/opt/nginx-1.10.2/logs/error.log"   nginx http access log file: "/opt/nginx-1.10.2/logs/access.log"   nginx http client request body temporary files: "client_body_temp"   nginx http proxy temporary files: "proxy_temp"   nginx http fastcgi temporary files: "fastcgi_temp"   nginx http uwsgi temporary files: "uwsgi_temp"   nginx http scgi temporary files: "scgi_temp"

5、编译

  [root@master nginx-1.10.2]# make

 ................

  make[1]: Leaving directory `/root/nginx-1.10.2'

6、安装

  [root@master nginx-1.10.2]# make install

  make -f objs/Makefile install   .............   make[1]: Leaving directory `/root/nginx-1.10.2'

[root@master nginx-1.10.2]# cd /opt/nginx-1.10.2/   [root@master nginx-1.10.2]# ls   conf  html  logs  sbin

7 、启动服务

[root@master nginx-1.10.2]# ./sbin/nginx

2021-5-10更新

tar -zxvf nginx-1.20.0.tar.gz  cd nginx-1.20.0/  ./configure --prefix=/usr/local/nginx  sudo yum install -y pcre-devel ./configure --prefix=/usr/local/nginx  make sudo make install cd /usr/local/nginx/ sudo  ./sbin/nginx

0 人点赞