首先得确认是否安装了编译工具和开发包,如果没有先安装编译工具及开发包。
yum install -y gcc cmake make gcc-c++ apr* automake autoconf libxml2 libxml2-devel openssl openssl-devel curl* libjpeg* libpng* freetype* zlib-devel zip unzip gzip ncurses* pcre-devel bzip2* gd gd-devel kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* php-common php-gd ncurses* libtool* patch libmcrypt libmcrypt-devel mcrypt mhash --skip-broken |
1 依赖库配置,编译和安装Nginx1.9.0
先创建一个名为nginx且没有登录权限
的用户和一个名为nginx的用户组,然后安装nginx所需的依赖库和依赖包,最后通过.configure
进 行安装的详细配置。另外,补录一个pcre的tar包备份地址:https://o3cex9zsl.qnssl.com/libs/nginx /pcre-8.36.tar.gz,以及一个zlib的tar包备份地址:https://o3cex9zsl.qnssl.com/libs /nginx/zlib-1.2.8.tar.gz。
#######新建nginx用户和nginx组 [root@typecodes ~]# groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx #######yum安装nginx必须的依赖库 [root@typecodes ~]# yum -y install openssl openssl-devel libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed #######官网下载Nginx1.9.0的tar包,然后解压到服务器上 [root@typecodes ~]# wget -c http://nginx.org/download/nginx-1.9.0.tar.gz [root@typecodes ~]# tar -zxf nginx-1.9.0.tar.gz && cd nginx-1.9.0 #######下载pcre的tar包并解压,以便支持Nginx的Rewrite功能 [root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/php/pcre-8.36.tar.gz && tar -zxf pcre-8.36.tar.gz #######下载zlib的tar包并解压,以便支持Nginx的Gzip压缩功能 [root@typecodes nginx-1.9.0]# wget -c http://git.typecodes.com/libs/nginx/zlib-1.2.8.tar.gz [root@typecodes nginx-1.9.0]# tar -zxf zlib-1.2.8.tar.gz #######新建Nginx1.9.0安装时所需要的目录 [root@typecodes nginx-1.9.0]# cd /var/tmp/ && mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi} [root@typecodes tmp]# mkdir -p /var/run/nginx && cd ~/nginx-1.9.0 |
准备工作做好后,就开始正式配置Nginx-1.9.0的安装明细了。注意,在使用下面这条configure
参数配置时,一定要先把反斜杠“\”后面添加的注释文字去掉!!!
[root@typecodes nginx-1.9.0]# ./configure \ --prefix=/usr/share/nginx \ [Nginx安装目录] --sbin-path=/usr/sbin/nginx \ [Nginx的sbin目录] --conf-path=/etc/nginx/nginx.conf \ [Nginx的配置文件] --error-log-path=/var/log/nginx/error.log \ [Nginx的错误日志] --http-log-path=/var/log/nginx/access.log \ [Nginx的访问日志] --pid-path=/var/run/nginx/nginx.pid \ [Nginx的进程ID] --lock-path=/var/lock/nginx.lock \ --user=nginx \ [Nginx所属用户] --group=nginx \ [Nginx所属用户组] --with-http_ssl_module \ [Nginx的ssl模块] --with-http_spdy_module \ [Nginx的Google spdy模块] --with-http_dav_module \ --with-http_flv_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module \ --with-http_stub_status_module \ --with-http_sub_module \ --with-http_random_index_module \ --with-http_degradation_module \ --with-http_secure_link_module \ --with-http_gzip_static_module \ [Nginx的gzip压缩模块] --with-http_perl_module \ --with-pcre=pcre-8.36 \ [pcre的安装目录] --with-zlib=zlib-1.2.8 \ [pcre的安装目录] --with-debug \ [允许DEBUG] --with-file-aio \ --with-mail \ --with-mail_ssl_module \ --http-client-body-temp-path=/var/tmp/nginx/client_body \ --http-proxy-temp-path=/var/tmp/nginx/proxy \ --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-stream \ [Nginx1.9.0特有的stream模块] --with-ld-opt="-Wl,-E" [gcc的编译优化] |
配置过程大概需要5分钟左右,部分截图如下:
2 配置完后,就可以直接编译和安装了
最后,直接使用执行这条命令[root@typecodes nginx-1.9.0]# make && make install
进行安装即可。其中,make命令和make install命令的执行结果附图如下:
3 配置Nginx1.9.0,使之正常工作
成功安装Nginx1.9.0后,我们需要进行一些配置,包括开机启动、SSL/HTTPS服务等。其中,Nginx服务控制脚本nginx
见文章《Nginx服务启动、停止和重启等操作的SHELL脚本》。