安装Nginx:
安装Nginx之前需要安装pcre,进入/usr/local/src目录,解压pcre,进入pcre解压目录,执行以下命令进行编译安装:
[root@linuxidc pcre-8.35]# ./configure –prefix=/usr/local/pcre && make && make install
创建web组合web用户,不允许web用户直接登录系统:
[root@linuxidc pcre-8.35]# groupadd web
[root@linuxidc pcre-8.35]# useradd -g web web -s /bin/false
编译安装nginx,解压,进入安装目录,执行以下命令:
[root@linuxidc nginx-1.7.0]# ./configure –prefix=/usr/local/nginx –without-http_memcached_module –user=web –group=web –with-http_stub_status_module –with-openssl=/usr/ –with-pcre=/usr/local/src/pcre-8.35
注意:–with-pcre=/usr/local/src/pcre-8.31指向的是源码包解压的路径,而不是安装的路径,否则会报错
编译安装:
[root@linuxidc nginx-1.7.0]# make && make install
编辑Nginx启动命令:
[root@linuxidc nginx-1.7.0]# 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.confnginxd=/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 /usr/local/nginx/logs/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
赋予nginx执行权限:
[root@linuxidc nginx-1.7.0]# chmod 775 /etc/init.d/nginx
设置nginx开机启动:
[root@linuxidc nginx-1.7.0]# chkconfig nginx on
启动nginx:
[root@linuxidc nginx-1.7.0]# service nginx start
测试Nginx安装和启动状态:
至此,Nginx安装完毕,待安装好PHP后再做对PHP的支持和指定自定义发布目录设置。
创建web目录:
[root@linuxidc nginx-1.7.0]# mkdir -p /home/data/web