即将新官上任,有很多环境要自己搭建,现将自己搭建的每一个过程都记录下来,希望给自己做个保存,也想给有同样需要的朋友提供参考,减少不必要的时间
我用的是ubuntu11.04版本,绝对是全新的环境,参照的ngxin官网的英文步骤操作的
nginx官网安装步骤
http://nginx.org/en/docs/install.html
一、准备工作
a. 到ngxin官网下载nginx-1.3.14.tar.gz文件
b.下载所需的库,以下在各官网都能下到,pcre、openssl、zlib,这些都是ngxin安装过程中所必须的,必须先编译安装好,或者直接用apt-get install,本人想试一下源码安装,另外以后是负责网站环境,所以还是自己安装的好
二、开始安装
解压zlib、openssl、pcre库,供下面nginx安装使用
cd /usr/src tar zxvf zlib-1.2.7.tar.gz tar zxvf openssl-1.0.1e.tar.gz tar zxvf pcre-8.21.tar.gz
安装nginx
cd /usr/src tar nginx-1.3.14.tar.gz cd nginx-1.3.14 ./configure --prefix=/usr/local/nginx --with-openssl=../openssl-1.0.1e --with-pcre=../pcre-8.21 --with-zlib=../zlib-1.2.7 #这里的参数可以参考官网说明,每一项都很简单 make make install
至此nginx已经安装完成,在/usr/local/nginx目录下
但是ngxin还没有启动,此时先手动启动nginx
/usr/local/nginx/sbin/nginx ps -e | grep nginx 如果能看到nginx进程说明已经启动成功 wget http://localhost进行访问已经可以访问,或者直接用浏览器访问ip地址也可以看到nginx的 欢迎页面
三、将ngxin添加到服务,并且设为开机启动
cd /etc/init.d vi 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.conf nginxd=/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" # 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: " $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " $nginxd -s stop RETVAL=$? echo [ $RETVAL = 0 ] } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " pkill -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 保存退出 chmod u+x nginx 此时服务nginx已经添加,以下命令就可以了 service nginx start service nginx stop service nginx restart service nginx reload service nginx status service nginx help 最后把nginx设为开机启动 update-rc.d -f nginx defaults 这样下次重启机器的时候,nginx就会自动启动了