Linux操作系统:CentOS6.5 64bit
最新版Nginx: 1.9.3
1、下载Nginx
[root@linuxidc softs]# wget
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]# 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]# 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
启动: