1、安装必要的编译环境
yum install gcc gcc-c++
2、安装需要的组件
安装PCRE库
cd /usr/local/src
wgethttp://ufpr.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure--prefix=/usr/local/pcre
make
make install
安装zlib库
cd /usr/local/src
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure--prefix=/usr/local/zlib
make
make install
安装ssl
cd /usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1s.tar.gz
tar -zxvf openssl-1.0.1s.tar.gz
cd openssl-1.0.1s
./config--prefix=/usr/local/openssl
make
make install
安装Tengine
cd /usr/local/src
wgethttp://tengine.taobao.org/download/tengine-2.1.2.tar.gz
tar -zxvftengine-2.1.2.tar.gz
cdtengine-2.1.2
./configure--prefix=/usr/local/Nginx
--with-pcre=/usr/local/src/pcre-8.38\
--with-openssl=/usr/local/src/openssl-1.0.1s\
--with-zlib=/usr/local/src/zlib-1.2.8\
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_concat_module \
--with-http_stub_status_module \
make &&make install
注意配置的时候 –with-pcre 、–with-openssl、–with-zlib的路径为源文件的路径,可不填,后面的模块如果不想安装也不填。
4、手动启动Nginx
报错
/usr/local/Nginx/sbin/Nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory
解决方法::
32位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib
64位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib64
再次执行
启动成功,看到欢迎界面
5、配置服务开机自启动
vi/etc/init.d/Nginx
#加入如下内容
#!/bin/bash # # 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 TENGINE_HOME="/usr/local/Nginx/" Nginx=$TENGINE_HOME"sbin/Nginx" prog=$(basename $Nginx) Nginx_CONF_FILE=$TENGINE_HOME"conf/Nginx.conf" [ -f /etc/sysconfig/Nginx ] && /etc/sysconfig/Nginx lockfile=/var/lock/subsys/Nginx start() { [ -x $Nginx ] || exit 5 [ -f $Nginx_CONF_FILE ] || exit 6 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 killall -9 Nginx } 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@H_473_404@
设置权限并启动