Linux下安装Nginx1.9.3-0303(本人亲手实践)
Posted ORACLE-fans
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下安装Nginx1.9.3-0303(本人亲手实践)相关的知识,希望对你有一定的参考价值。
Linux下安装Nginx1.9.3
Linux操作系统 Oel 5.8 64bit
最新版nginx: 1.9.3
最近同事让我帮忙搞 ngix,两天时间 安装、配置搞定了。继续
Nginx 1.9.3 发布下载,高性能 Web 服务器
1、下载Nginx1.9.3
下载地址: http://nginx.org/download/nginx-1.9.3.tar.gz |
2、安装依赖的库
检查以下软件包是否安装
[[email protected] ~]# rpm -qa gcc gcc-4.1.2-52.el5 [[email protected] ~]# rpm -qa automake automake-1.9.6-2.3.el5 [[email protected] ~]# rpm -qa autoconf autoconf-2.59-12 [[email protected] ~]# rpm -qa libtool libtool-1.5.22-7.el5_4 [[email protected] ~]# rpm -qa make make-3.81-3.el5 [[email protected] ~]# rpm -qa libxml2 libxml2-2.6.26-2.1.12.0.1.el5_7.2 libxml2-2.6.26-2.1.12.0.1.el5_7.2 [[email protected] ~]# rpm -qa libxml2-devel libxml2-devel-2.6.26-2.1.12.0.1.el5_7.2 libxml2-devel-2.6.26-2.1.12.0.1.el5_7.2 [[email protected] lib64]# rpm -qa libxslt-devel libxslt-devel-1.1.17-2.0.3.el5_2.2
随后安装 perl相关补丁包 [[email protected] ~]# rpm -qa perl-devel |
3、安装pcre
用于重写rewrite
下载地址: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
将pcre安装到 /usr/local/src
[[email protected] softs]# cd /usr/local/src/
[[email protected] src]# tar pcre-8.37.tar.gz [[email protected] src]# cd pcre-8.37
[[email protected] pcre-8.37]# ./configure [[email protected] pcre-8.37]# make [[email protected] pcre-8.37]# make install |
4、安装zlib
用于gzip压缩
安装到/usr/local/src
下载地址: http://zlib.net/zlib-1.2.8.tar.gz
[[email protected] src]# tar -zxv zlib-1.2.8.tar.gz
[[email protected] src]# cd zlib-1.2.8 [[email protected]racle11g zlib-1.2.8]# ./configure [[email protected] zlib-1.2.8]# make [[email protected] zlib-1.2.8]# make install |
5、安装openssl
用于ssl
安装到/usr/local/src
下载地址: http://www.openssl.org/source/openssl-1.0.2g.tar.gz
[[email protected] src]# tar -zxvf openssl-1.0.2g.tar.gz
[[email protected] src]# cd openssl-1.0.2g [[email protected] openssl-1.0.2g]# ./Configure [[email protected] openssl-1.0.2g]# make [[email protected] openssl-1.0.2g]# make install |
6、安装Nginx
安装到/usr/local/nginx
[[email protected] local]# cd /usr/local [[email protected] local]# cd nginx-1.9.3
[[email protected] nginx-1.9.3]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.2g
直接复制以上信息,不需修改 [[email protected] nginx-1.9.3]# make [[email protected] nginx-1.9.3]# make install |
7、设置开机自启动
在/etc/init.d/下建立nginx文件
[[email protected] init.d]# vi nginx
写入以下内容:
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it‘s not for everyone. # processname: nginx # pidfile: /usr/local/nginx/logs/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
赋予可执行权限
[[email protected] init.d]# chmod a+x /etc/init.d/nginx
设置开机启动
[[email protected] init.d]# chkconfig --add /etc/init.d/nginx [[email protected] init.d]# chkconfig nginx on
启动:
[[email protected] lib64]# service nginx start Starting nginx: [ OK ] |
8、启动报错处理
[[email protected] init.d]# service nginx start Starting nginx: /usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory [FAILED]
使用ldd看nginx包含的动态函式库
[[email protected] src]# ldd $(which /usr/local/nginx/sbin/nginx) linux-vdso.so.1 => (0x00007fff89fff000) libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003978400000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x000000397b800000) libpcre.so.1 => not found libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007ffd9a115000) libz.so.1 => /lib64/libz.so.1 (0x0000003977c00000) libc.so.6 => /lib64/libc.so.6 (0x0000003978000000) /lib64/ld-linux-x86-64.so.2 (0x0000003977800000) libfreebl3.so => /lib64/libfreebl3.so (0x000000397ac00000) libdl.so.2 => /lib64/libdl.so.2 (0x0000003978800000) [[email protected] src]# cd /
可以看到 libpcre.so.1 => not found
解决方法:
进入/lib64目录中手动链接下
[[email protected] init.d]# cd /lib64/
[[email protected] lib64]# ln -s libpcre.so.0.0.1 libpcre.so.1
然后再启动。 |
以上是关于Linux下安装Nginx1.9.3-0303(本人亲手实践)的主要内容,如果未能解决你的问题,请参考以下文章