首页 > 代码库 > nginx安装

nginx安装

1、必要软件准备
     * 安装pcre
为了支持rewrite功能,我们需要安装pcre

# yum install pcre* //如过你已经装了,请跳过这一步


     * 安装openssl
需要ssl的支持,如果不需要ssl支持,请跳过这一步

# yum install openssl*


2、安装nginx执行如下命令:

# ./configure --prefix=/usr/local/nginx \
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre

–with-http_stub_status_module:支持nginx状态查询
–with-http_ssl_module:支持https
–with-http_spdy_module:支持google的spdy,这个必须有ssl的支持
–with-pcre:为了支持rewrite重写功能,必须制定pcre

#make && make install  --编译安装


3、启动、关闭、重置nginx启动:直接执行以下命令,nginx就启动了,不需要改任何配置文件

/usr/local/nginx-1.5.1/sbin/nginx

关闭:

/usr/local/nginx-1.5.1/sbin/nginx -s stop


4、将nginx加入本地服务和自启动项

     *在/etc/init.d下创建名为nginx的脚本,内容如下

#!/bin/sh

####BEGIN INFO
# DateTime: 2014-12-12
#Created by Morgan <yu_liang520@126.com>
#Applicable to Nginx as a system service
# chkconfig: 35 85 15
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
####END INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

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
}

restart() {
configtest || return $?
stop
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 


*将nginx加入到本地服务并随系统自动启动

chkconfig --add nginx
chkconfig nginx on


*添加nginx脚本的执行权限

chmod +x /etc/init.d/nginx


*控制nginx命令

service nginx stop/start/restart


本文出自 “亮公子” 博客,请务必保留此出处http://iyull.blog.51cto.com/4664834/1864377

nginx安装