快捷搜索:   服务器  安全  linux 安全  MYSQL  dedecms

ubuntu server 9.04下编译安装nginx

首先编译nginx所需的软件包:

1.Perl 5 Compatible Regular Expression Library - development files

sudo apt-get install libpcre3-dev      

2.SSL development libraries, header files and documentation

sudo apt-get install libssl-dev   

3.make 工具

sudo apt-get install make

创建启用nginx所使用的用户组和用户

sudo groupadd www

sudo useradd -g www www

sudo mkdir -v -p /www/htdocs/site1

sudo chown -R www:www /www/htdocs/site1

然后下载nginx源码包

wget http://sysoev.ru/nginx/nginx-0.8.9.tar.gz

开始编译安装nginx

tar zxvf nginx-0.8.9.tar.gz

cd nginx-0.8.9

./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module

sudo make

sudo make install

然后建立nginx服务控制脚本程序

sudo nano /etc/init.d/nginx

输入以下内容:

#! /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 INFOPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDAEMON=/usr/local/webserver/nginx/sbin/nginxNAME=nginxDESC=nginxtest -x $DAEMON || exit 0# Include nginx defaults if availableif [ -f /etc/default/nginx ] ; then . /etc/default/nginxfiset -e. /lib/lsb/init-functionscase "$1" instart) echo -n "Starting $DESC: " start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;;stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON || true echo "$NAME." ;;restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile \ /var/run/$NAME.pid --exec $DAEMON || true sleep 1 start-stop-daemon --start --quiet --pidfile \ /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;;reload)echo -n "Reloading $DESC configuration: "start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \--exec $DAEMON || trueecho "$NAME.";;status)status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?;;*) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 exit 1 ;;esacexit 0#! /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 INFOPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDAEMON=/usr/local/webserver/nginx/sbin/nginxNAME=nginxDESC=nginxtest -x $DAEMON || exit 0# Include nginx defaults if availableif [ -f /etc/default/nginx ] ; then . /etc/default/nginxfiset -e. /lib/lsb/init-functionscase "$1" in  start) echo -n "Starting $DESC: " start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;;  stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \ --exec $DAEMON || true echo "$NAME." ;;  restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile \ /var/run/$NAME.pid --exec $DAEMON || true sleep 1 start-stop-daemon --start --quiet --pidfile \ /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true echo "$NAME." ;;  reload)      echo -n "Reloading $DESC configuration: "      start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \          --exec $DAEMON || true      echo "$NAME."      ;;  status)      status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?      ;;  *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 exit 1 ;;esacexit 0然后就可以通过sudo /etc/init.d/nginx start(stop|restart|status)等命令及参数来控制nginx和查看状态信息了至于nginx的具体配置,留待下一次继续讨论学习。在测试本次编译安装的同时,我在另一台虚拟机us904上通过sudo apt-get install nginx安装nginx来查看两种方式的不同,发现nginx_0.6.35-0ubuntu1_i386.deb文件主要有以下文件拷贝过程sudo dpkg -L nginx/./usr/usr/sbin/usr/sbin/nginx/usr/share/usr/share/doc/usr/share/doc/nginx/usr/share/doc/nginx/changelog.gz/usr/share/doc/nginx/README/usr/share/doc/nginx/copyright/usr/share/doc/nginx/NEWS.Debian.gz/usr/share/doc/nginx/changelog.Debian.gz/usr/share/man/usr/share/man/man1/usr/share/man/man1/nginx.1.gz/etc/etc/nginx/etc/nginx/sites-available/etc/nginx/sites-available/default/etc/nginx/sites-enabled/etc/nginx/conf.d/etc/nginx/fastcgi_params/etc/nginx/koi-utf/etc/nginx/koi-win/etc/nginx/mime.types/etc/nginx/nginx.conf/etc/nginx/win-utf/etc/init.d/etc/init.d/nginx/etc/logrotate.d/etc/logrotate.d/nginx/var/var/log/var/log/nginx/var/lib/var/lib/nginx/var/www/var/www/nginx-default/var/www/nginx-default/50x.html/var/www/nginx-default/index.html由此猜想在生产环境中是否可以避免安装过多软件包,而直接替换/usr/sbin/nginx文件来实现,具体运行稳定性有待验证。ps:1.如果不想输入命令时带有sudo,可以通过下面方式切换至rootA.sudo -s -H 输入当前用户密码B.sudo passwd root 设置root密码    su root 输入root密码2.查看某个包具体所在的包名,可以通过sudo apt-cache search *** 来查找
顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论