lizongbo at 618119.com 工作,生活,Android,前端,Linode,Ubuntu,nginx,java,apache,tomcat,Resin,mina,Hessian,XMPP,RPC

2010年10月22日

Ubuntu Server 10.04 LTS的Linux上编译安装配置nginx0.8.52

Filed under: Linux,nginx,SSL — 标签:, , , , — lizongbo @ 13:37

Server 10.04 LTS的Linux上安装配置nginx0.8.52

操作系统是linode上的Linux:Ubuntu Server 10.04 LTS。
nginx的最新版本是:0.8.52
http://nginx.org/download/nginx-0.8.52.tar.gz
来源:http://nginx.org/en/download.html
nginx依赖的PCRE库,最新版本是:8.10:
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
来源:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
OpenSSL的最新版本是:1.0.0a:
http://www.openssl.org/source/openssl-1.0.0a.tar.gz
来源:http://www.openssl.org/source/
zlib的最新版本是:1.2.5:
http://zlib.net/zlib-1.2.5.tar.gz
在/usr/local目录下创建app目录,所有应用都安装配置到这个目录下面:
root@618119.com:/usr/local# sudo mkdir app
root@618119.com:/usr/local# cd ./app
然后下载安装程序:
root@618119.com:/usr/local/app# wget http://nginx.org/download/nginx-0.8.52.tar.gz
root@618119.com:/usr/local/app# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
root@618119.com:/usr/local/app# wget http://www.openssl.org/source/openssl-1.0.0a.tar.gz
root@618119.com:/usr/local/app# wget http://zlib.net/zlib-1.2.5.tar.gz
再解压压缩包:
root@618119.com:/usr/local/app# tar -zxvf *
root@618119.com:/usr/local/app# tar -zxvf pcre*
root@618119.com:/usr/local/app# tar -zxvf *
root@618119.com:/usr/local/app# tar -zxvf zlib*
由于缺少gcc等编译器,需要先运行:
root@618119.com:/usr/local/app# apt-get install gcc libc6-dev build-essential
进入到nginx解压得到的目录:
root@618119.com:/usr/local/app# cd nginx-*
运行configure命令,将nginx的安装目录设置为/usr/local/app/nginx。
with-http_stub_status_module参数是启用stub_status监控。
root@618119.com:/usr/local/app/nginx-0.8.52#  ./configure –prefix=/usr/local/app/nginx –user=nginx –group=nginx –with-http_ssl_module –with-http_stub_status_module –with-pcre=/usr/local/app/pcre-8.10 –with-openssl=/usr/local/app/openssl-1.0.0a –with-zlib=/usr/local/app/zlib-1.2.5
然后再运行make进行编译:
root@618119.com:/usr/local/app/nginx-0.8.52# make
再运行:make install,
root@618119.com:/usr/local/app/nginx-0.8.52# make install

还需要添加nginx用户组(未添加用户组就启动的话:会提示[emerg]: getpwnam(“nginx”) failed):
root@618119.com:/usr/local/app/nginx# sudo adduser –system –no-create-home –disabled-login –disabled-password –group nginx
进入到nginx的sbin目录用-t参数检查配置文件是否ok:
root@618119.com:/usr/local/app/nginx# cd sbin/
root@618119.com:/usr/local/app/nginx/sbin# sudo ./nginx -t
the configuration file /usr/local/app/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/app/nginx/conf/nginx.conf test is successful

这样就在linode的VPS上将nginx0.8.52安装好了。
root@618119.com:/usr/local/app/nginx/sbin# ./nginx
[emerg]: bind() to 0.0.0.0:80 failed (13: Permission denied)
root@618119.com:/usr/local/app/nginx/sbin#sudo ./nginx
(不用root启动的话,会提示:[emerg]: bind() to 0.0.0.0:80 failed (13: Permission denied))
启动成功后访问http 80端口可以看到Welcome to nginx!

接下来制作nginx系统服务启动的脚本,参考 http://articles.slicehost.com/2007/10/17/ubuntu-lts-adding-an-nginx-init-script

#! /bin/sh

### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/app/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi

set -e

case “$1” in
start)
echo -n “Starting $DESC: ”
start-stop-daemon –start –quiet –pidfile /usr/local/app/nginx/logs/$NAME.pid \
–exec $DAEMON — $DAEMON_OPTS
echo “$NAME.”
;;
stop)
echo -n “Stopping $DESC: ”
start-stop-daemon –stop –quiet –pidfile /usr/local/app/nginx/logs/$NAME.pid \
–exec $DAEMON
echo “$NAME.”
;;
restart|force-reload)
echo -n “Restarting $DESC: ”
start-stop-daemon –stop –quiet –pidfile \
/usr/local/app/nginx/logs/$NAME.pid –exec $DAEMON
sleep 1
start-stop-daemon –start –quiet –pidfile \
/usr/local/app/nginx/logs/$NAME.pid –exec $DAEMON — $DAEMON_OPTS
echo “$NAME.”
;;
reload)
echo -n “Reloading $DESC configuration: ”
start-stop-daemon –stop –signal HUP –quiet –pidfile /usr/local/app/nginx/logs/$NAME.pid \
–exec $DAEMON
echo “$NAME.”
;;
*)
N=/etc/init.d/$NAME
echo “Usage: $N {start|stop|restart|force-reload}” >&2
exit 1
;;
esac

exit 0

再运行命令: sudo /usr/sbin/update-rc.d -f nginx defaults,将nginx安装为默认服务。

这样在linode里对Ubuntu重启之后,nginx服务也自动启动了。

一条评论 »

  1. 启动一直报错,到这儿看看,原来我忘记了小于1024的一定要用root起,any way, thank u

    Reply

    评论 by crazyxiao — 2012年02月16日 @ 13:43

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress