共计 4964 个字符,预计需要花费 13 分钟才能阅读完成。
Linux 操作系统:CentOS6.5 64bit
最新版 Nginx: 1.9.3
Nginx 1.9.3 发布下载,高性能 Web 服务器 http://www.linuxidc.com/Linux/2015-07/120178.htm
1、下载 Nginx
[root@linuxidc softs]# wget http://nginx.org/download/nginx-1.9.3.tar.gz
2、安装依赖的库
[root@linuxidc softs]# yum -y install gcc automake autoconf libtool make libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed
[root@linuxidc softs]# yum install gcc gcc-c++
3、安装 pcre,用于重写 rewrite
[root@linuxidc softs]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
将 pcre 安装到 /usr/local/src
[root@linuxidc softs]# cd /usr/local/src/
[root@linuxidc src]# tar pcre-8.37.tar.gz
[root@linuxidc src]# cd pcre-8.37
[root@linuxidc pcre-8.37]# ./configure
[root@linuxidc pcre-8.37]# make
[root@linuxidc pcre-8.37]# make install
4、安装 zlib,用于 gzip 压缩
安装到 /usr/local/src
[root@linuxidc src]# wget http://zlib.net/zlib-1.2.8.tar.gz
[root@linuxidc src]# tar -zxv zlib-1.2.8.tar.gz
[root@linuxidc src]# cd zlib-1.2.8
[root@linuxidc zlib-1.2.8]# ./configure
[root@linuxidc zlib-1.2.8]# make
[root@linuxidc zlib-1.2.8]# make install
5、安装 openssl,用于 ssl
安装到 /usr/local/src
[root@linuxidc src]# wget http://www.openssl.org/source/openssl-1.0.2d.tar.gz
[root@linuxidc src]# tar -zxvf openssl-1.0.2d.tar.gz
[root@linuxidc src]# cd openssl-1.0.2d
6、安装 Nginx
安装到 /usr/local/nginx
[root@linuxidc softs]# cd /usr/local
[root@linuxidc local]# pwd
/usr/local
[root@linuxidc local]#
[root@linuxidc local]# cd nginx-1.9.3
[root@linuxidc 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.1d
[root@linuxidc nginx-1.9.3]# make
[root@linuxidc nginx-1.9.3]# make install
7、设置开机自启动
在 /etc/init.d/ 下建立 nginx 文件
[root@linuxidc 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
赋予可执行权限
[root@linuxidc init.d]# chmod a+x /etc/init.d/nginx
设置开机启动
[root@linuxidc init.d]# chkconfig –add /etc/init.d/nginx
[root@linuxidc init.d]# chkconfig nginx on
启动:
[root@linuxidc lib64]# service nginx start
Starting nginx: [OK]
[root@linuxidc lib64]#
8、启动报错处理
[root@linuxidc 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 包含的动态函式库
[root@linuxidc 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)
[root@linuxidc src]# cd /
可以看到 libpcre.so.1 => not found
解决方法:
进入 /lib64 目录中手动链接下
[root@linuxidc init.d]# cd /lib64/
[root@linuxidc lib64]# ln -s libpcre.so.0.0.1 libpcre.so.1
然后再启动。
更多 Nginx 相关教程见以下内容 :
CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm
Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm
Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-08/120933.htm