配置环境
yum -y install gcc openssl-devel zlib-devel pcre-devel
yum -y install gcc gcc-c++ autoconf automake
安装pcre
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.zip
unzip pcre-8.35.zip
cd pcre-8.35
./configure
make && make install
安装OpenSSL-1.0.1e
wget http://www.openssl.org/source/openssl-1.0.1e.tar.gz
tar zxvf openssl-1.0.1e.tar.gz
cd openssl-1.0.1e
./config
make
make install
安装Nginx
wget http://nginx.org/download/nginx-1.4.7.tar.gz
tar -zxvf nginx-1.4.7.tar.gz
./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_gzip_static_module --with-http_stub_status_module --with-mail --with-openssl=../openssl-1.0.1e --with-mail_ssl_module --with-debug --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre=../pcre-8.33/
make
make install
让Nginx以服务形式启动
vim /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# 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: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx #modify
nginx_config=/usr/local/nginx/conf/nginx.conf #modify
nginx_pid=/var/run/nginx.pid #modify
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
注意:这里面有三行
nginxd=/usr/local/nginx/sbin/nginx #modify
nginx_config=/usr/local/nginx/conf/nginx.conf #modify
nginx_pid=/var/run/nginx.pid #modify
需要根据自己安装的路径来修改配置,nginx各文件的安装路径要与实际安装的一致。
- 保存nginxd脚本,赋予执行权限,添加服务和开机启动
chmod +x /etc/init.d/nginx
chkconfig --add nginx
- 启动
service nginx start
service nginx restart
service nginx stop
访问:http://127.0.0.1/测试
安装出现的问题及解决方法
问题1
** make[1]: *** [/opt/pcre//Makefile] Error 127
解决方法:
--with-pcre=../pcre-8.33/
--with-pcre=DIR 是设置源码目录,而不是编译安装后的目录。问题2
** make[1]: *** [/opt/openssl//Makefile] Error 127
解决方法:
--with-openssl=../openssl-1.0.1e
--with-openssl=DIR 是设置源码目录,而不是编译安装后的目录。