安装环境:
• 系统:Centos6.4
• 软件:Nginx1.11.1
• 依赖:Pcre、Zlib、Openssl
所需文件:
1.pcre-8.38.tar.gz
2.openssl-1.0.2h.tar.gz
3.zlib-1.2.8.tar.gz
4.nginx-1.11.1.tar.gz
安装顺序:顺序安装
安装方式:*.tar.gz源代码包安装方式编译安装
一.安装pcre
1.解压pcre-8.38.tar.gz tar -zxvf pcre-8.38.tar.gz:tar
2.进入解压目录 cd pcre-8.38
3.编译前执行配置 ./configure
4.编译 make
5.安装 make install
6.安装完成
二.安装openssl
1.解压oenssl-xxx.tar.gz
2.进入解压目录,执行"./config"
3.编译(make)并安装(make install)
三.安装zlib
1.解压zlib-xxx.tar.gz
2.进入解压目录,执行"./configure"
3.编译(make)并安装(make install)
四.安装nginx
1.解压nginx-xxx.tar.gz
2.进入解压目录,执行"./configure"
3.编译(make)并安装(make install)
目录结构:
. conf 配置文件
. html 静态资源
. logs 日志
. sbin 命令工具
启动并校验
启动: ./nginx
检验:
1.命令查询: ps -ef | grep nginx | grep -v grep
2.浏览器查看: http://192.168.226.150/
配置开机自动启动:
nginx文件内容:
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: NGINX is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
先将nginx服务加入chkconfig管理列表: chkconfig --add /etc/init.d/nginx
解决:
chmod +x /etc/init.d/nginx
原因:Linux和Window文本文件的行结束标志不一样,Linux下是以"\n"表示回车换行,Windows下是以"\r\n"表示回车换行;
再解决:命令安装并转化
五.可能遇到的问题:
1.需要c++编译器(编译前执行配置出现"./configure")
解决:去media安装盘查找c++编译器,并安装
1.cd /media
2.cd CentOS_6.4_Final/
3.cd Packages/ (有时要进入虚拟机才能显示)
4. rpm -ivh libstdc++-devel-4.4.7-3.el6.i686.rpm
5.rpm -ivh gcc-c++-4.4.7-3.el6.i686.rpm
2."./nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory"
解决:配置相关路径连接
32位: ln -s /usr/local/lib/libpcre.so.1 /lib
64位: ln -s /usr/local/lib/libpcre.so.1 /lib64