返回文章列表

[10/21 周主题] – 安装和配置Nginx

马上Nginx将会应用到公司的第一个实战项目上,为了方便开发和运维人员安装和配置Nginx,整理了下面的内容。 我们的服务器全部采用CentOS,因此下面的配置也是基于CentOS来配置的。 安装流程: [code lang="c"] cd /opt/ yum install gc...

2 分钟阅读

马上Nginx将会应用到公司的第一个实战项目上,为了方便开发和运维人员安装和配置Nginx,整理了下面的内容。

我们的服务器全部采用CentOS,因此下面的配置也是基于CentOS来配置的。
安装流程:
[code lang="c"]
cd /opt/

yum install gcc openssl-devel pcre-devel zlib-devel

wget http://nginx.org/download/nginx-0.8.38.tar.gz

wget http://github.com/gnosek/nginx-upstream-fair/tarball/master

tar –zxvf nginx-0.8.38.tar.gz

tar –zxvf gnosek-nginx-upstream-fair-2131c73.tar.gz

cd nginx-0.8.38

./configure
--with-http_stub_status_module
--add-module=/opt/gnosek-nginx-upstream-fair-2131c73

make & make install
[/code]

正常一步步走下面是不会出问题的,前提确保你的服务器网络可用。

Nginx启动脚本:

[code lang="c"]
#!/bin/bash
# Nginx Manage Script
#
# 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=/var/run/nginx.pid
lockfile=/var/lock/subsys/nginx

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 $lockfile
return $RETVAL

}

# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile $nginx_pid
}

# reload nginx service functions.
reload() {

echo -n $"Reloading $prog: "
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
[/code]

将上面的脚本放在 /etc/init.d/nginx 文件里面

[code lang="c"]
chmod +x /etc/init.d/nginx
[/code]

[code lang="c"]
/etc/init.d/nginx start
[/code]

评论交流

暂无评论,欢迎留下你的想法