Nginx編譯安裝

一、Nginx下載地址:http://nginx.org/en/download.htmlhtml

二、下載Nginx:nginx

[root@sunan ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
[root@sunan ~]# tar xzvf nginx-1.14.2.tar.gz

三、解壓後使Nginx的語法在vim中:vim

[root@sunan nginx-1.14.2]# cp -r contrib/vim/* ~/.vim/

四、查看Nginx的幫助:ide

[root@sunan nginx-1.14.2]# man man/nginx.8

五、編譯前查看configure支持哪些參數:ui

[root@sunan nginx-1.14.2]# ./configure --help

  --help                             print this message

  --prefix=PATH                      set installation prefix
  --sbin-path=PATH                   set nginx binary pathname
  --modules-path=PATH                set modules path
  --conf-path=PATH                   set nginx.conf pathname
  --error-log-path=PATH              set error log pathname
  --pid-path=PATH                    set nginx.pid pathname
  --lock-path=PATH                   set nginx.lock pathname

  --user=USER                        set non-privileged user for
                                     worker processes
  --group=GROUP                      set non-privileged group for
                                     worker processes

  --build=NAME                       set build name
  --builddir=DIR                     set build directory

  --with-select_module               enable select module
  --without-select_module            disable select module
  --with-poll_module                 enable poll module
  --without-poll_module              disable poll module

  --with-threads                     enable thread pool support

  --with-file-aio                    enable file AIO support

  --with-http_ssl_module             enable ngx_http_ssl_module

  --without-http_charset_module      disable ngx_http_charset_module
  --without-http_gzip_module         disable ngx_http_gzip_module

  --with-http_perl_module            enable ngx_http_perl_module
  --with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module
  --with-perl_modules_path=PATH      set Perl modules path
  --with-perl=PATH                   set perl binary pathname

  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache

  --without-mail_smtp_module         disable ngx_mail_smtp_module

六、預編譯Nginx:this

[root@sunan nginx-1.14.2]# ./configure --prefix=/home/sunan/nginx

預編譯報錯:code

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

解決辦法:server

[root@sunan nginx-1.14.2]# yum -y install pcre-devel

預編譯報錯:htm

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

解決辦法:ip

[root@sunan nginx-1.14.2]# yum install -y zlib-devel

執行成功:

[root@sunan nginx-1.14.2]# echo $?
0

七、預編譯完成以後生成中間文件:

[root@sunan nginx-1.14.2]# cd objs/
[root@sunan objs]# ll
total 84
-rw-r--r-- 1 root root 17763 May  7 21:59 autoconf.err
-rw-r--r-- 1 root root 39521 May  7 21:59 Makefile
-rw-r--r-- 1 root root  6806 May  7 21:59 ngx_auto_config.h
-rw-r--r-- 1 root root   657 May  7 21:59 ngx_auto_headers.h
-rw-r--r-- 1 root root  5725 May  7 21:59 ngx_modules.c
drwxr-xr-x 9 root root  4096 May  7 21:59 src

其中ngx_modules.c包含了將要被編譯進來的模塊。
八、編譯Nginx:

[root@sunan nginx-1.14.2]# make

編譯完成以後會生成大量的中間文件以及最終要運行的Nginx二進制文件,都在objs這個目錄下:

[root@sunan nginx-1.14.2]# cd objs/
[root@sunan objs]# ll
total 3784
-rw-r--r-- 1 root root   17763 May  7 21:59 autoconf.err
-rw-r--r-- 1 root root   39521 May  7 21:59 Makefile
-rwxr-xr-x 1 root root 3746336 May  7 22:08 nginx
-rw-r--r-- 1 root root    5345 May  7 22:08 nginx.8
-rw-r--r-- 1 root root    6806 May  7 21:59 ngx_auto_config.h
-rw-r--r-- 1 root root     657 May  7 21:59 ngx_auto_headers.h
-rw-r--r-- 1 root root    5725 May  7 21:59 ngx_modules.c
-rw-r--r-- 1 root root   31864 May  7 22:08 ngx_modules.o
drwxr-xr-x 9 root root    4096 May  7 21:59 src

若是是作Nginx升級的話這時不能make install,須要將目標nginx拷貝到安裝目錄中。
九、安裝Nginx:

[root@sunan nginx-1.14.2]# make install

十、安裝完成:

[root@sunan ~]# cd /home/sunan/nginx/
[root@sunan nginx]# ll
total 16
drwxr-xr-x 2 root root 4096 May  7 22:19 conf
drwxr-xr-x 2 root root 4096 May  7 22:19 html
drwxr-xr-x 2 root root 4096 May  7 22:19 logs
drwxr-xr-x 2 root root 4096 May  7 22:19 sbin
相關文章
相關標籤/搜索