centso6.2编译安装nginx1.4.6
一、编译安装nginx1.4.6
#软件包百度云地址下载
链接:http://pan.baidu.com/s/1eSPlAOa 密码:he22
#安装依赖库
yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch gettext glib2-devel bzip2-devel libuuid-devel docbook-style-xsl libxslt-devel gzip-devel freetype-devel
#安装pcre库
cd /usr/local/src/nginx
tar -xzvf ./pcre-8.33.tar.gz
cd ./pcre-8.33
./configure
make && make install
#安装zlib库
cd /usr/local/src/nginx
tar -xzvf ./zlib-1.2.8.tar.gz
cd ./zlib-1.2.8
./configure
make && make install
#安装ssl
cd /usr/local/src/nginx
tar -xzvf ./openssl-1.0.1e.tar.gz
#安装ngx_cache_purge-2.0
tar xf nginx/ngx_cache_purge-2.0.tar.gz
#安装Nginx
cd /usr/local/src/nginx
tar -xzvf ./nginx-1.4.7.tar.gz
cd ./nginx-1.4.7
mkdir /usr/local/nginx
./configure --prefix=/usr/local/nginx --user=www --group=www --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/nginx/pcre-8.33 --with-zlib=/usr/local/src/nginx/zlib-1.2.8 --with-openssl=/usr/local/src/nginx/openssl-1.0.1e --add-module=/usr/local/src/nginx/ngx_cache_purge-2.0 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_modul
make && make install
#启动服务
vim /usr/local/nginx/conf/nginx.conf
#user nobody 前面的#号去掉即可
/usr/local/nginx/sbin/nginx
#防火墙设置
echo "-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT" >>/etc/sysconfig/iptables
#创建nginx启动脚本
cat >>/etc/init.d/nginx <<EOF
#!/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
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/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 $nginx_pid
}
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
EOF
#访问nginx
http://ip
输入地址即可完成
每次说说:对于这类的服务安装,其实真的很简单,不懂的不用担心,花点时间好好看,肯定能搭建起来的,对于深入的nginx的使用,还需要多花时间。今天第一次发博客,给自己一个赞(*^__^*) 嘻嘻……