Nginx编译安装
1、Nginx下载地址:http://nginx.org/en/download.html
2、下载Nginx:
[ ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz [ ~]# tar xzvf nginx-1.14.2.tar.gz
3、解压后使Nginx的语法在vim中:
[ nginx-1.14.2]# cp -r contrib/vim/* ~/.vim/
4、查看Nginx的帮助:
[ nginx-1.14.2]# man man/nginx.8
5、编译前查看configure支持哪些参数:
[ 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
6、预编译Nginx:
[ nginx-1.14.2]# ./configure --prefix=/home/sunan/nginx
预编译报错:
./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.
解决办法:
[ nginx-1.14.2]# yum -y install pcre-devel
预编译报错:
./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.
解决办法:
[ nginx-1.14.2]# yum install -y zlib-devel
执行成功:
[ nginx-1.14.2]# echo $? 0
7、预编译完成之后生成中间文件:
[ nginx-1.14.2]# cd objs/ [ 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包含了将要被编译进来的模块。
8、编译Nginx:
[ nginx-1.14.2]# make
编译完成之后会生成大量的中间文件以及最终要运行的Nginx二进制文件,都在objs这个目录下:
[ nginx-1.14.2]# cd objs/ [ 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拷贝到安装目录中。
9、安装Nginx:
[ nginx-1.14.2]# make install
10、安装完成:
[ ~]# cd /home/sunan/nginx/ [ 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