linux系统源码安装nginx

242 阅读1分钟

准备工作

curl -O https://nginx.org/download/nginx-1.11.3.tar.gz

解压

tar xzf tar xzf nginx-1.11.3.tar.gz

构建配置

./configure

报错:

./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.

list 一下仓库里有哪些包:

[root@zjlyyq nginx-1.11.3]# yum list | grep pcre*
pcre.x86_64                                8.32-17.el7                @anaconda
pcre-devel.x86_64                          8.32-17.el7                @base
anope-pcre.x86_64                          2.0.9-3.el7                epel
ghc-pcre-light.x86_64                      0.4-13.el7                 epel
ghc-pcre-light-devel.x86_64                0.4-13.el7                 epel
ocaml-pcre.x86_64                          7.2.3-13.el7               epel
ocaml-pcre-devel.x86_64                    7.2.3-13.el7               epel
pcre.i686                                  8.32-17.el7                base
pcre-devel.i686                            8.32-17.el7                base
pcre-static.i686                           8.32-17.el7                base
pcre-static.x86_64                         8.32-17.el7                base
pcre-tools.x86_64                          8.32-17.el7                base
pcre2.i686                                 10.23-2.el7                base
pcre2.x86_64                               10.23-2.el7                base
pcre2-devel.i686                           10.23-2.el7                base
pcre2-devel.x86_64                         10.23-2.el7                base
pcre2-static.i686                          10.23-2.el7                base
pcre2-static.x86_64                        10.23-2.el7                base
pcre2-tools.x86_64                         10.23-2.el7                base
pcre2-utf16.i686                           10.23-2.el7                base
pcre2-utf16.x86_64                         10.23-2.el7                base
pcre2-utf32.i686                           10.23-2.el7                base
pcre2-utf32.x86_64                         10.23-2.el7                base
tcpcrypt.x86_64                            0.4-0.3.bb990b1b.el7       epel
tcpcrypt-devel.x86_64                      0.4-0.3.bb990b1b.el7       epel
tcpcrypt-libs.x86_64                       0.4-0.3.bb990b1b.el7       epel

源码安装,一般安装开发版本的,带devel后缀的:

yum install pcre-devel

在执行下 ./configure

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/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"

make

执行 make 命令

...
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
        -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/nginx-1.11.3'

install

sudo make install