Installing nginx on Debian
DRAFT …
Find latest version of nginx
http://sysoev.ru/en/ http://wiki.codemongers.com/NginxInstallOptions
Install a compiler otherwise: ./configure: error: C compiler gcc is not found
The command:
1 sudo apt-get install build-essential
Install pre-requisites otherwise you’ll get:
Configuration summary + threads are not used + PCRE library is not found + OpenSSL library is not found + md5 library is not used + sha1 library is not used + zlib library is not found
The command:
1 sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
Much better:
Configuration summary + threads are not used + using system PCRE library + using system OpenSSL library + md5 library is not used + sha1 library is not used + using system zlib library
Compile and install nginx
1 $ ./configure \ 2 --sbin-path=/usr/local/sbin \ 3 --conf-path=/etc/nginx/nginx.conf \ 4 --pid-path=/var/run/nginx.pid \ 5 --error-log-path=/var/log/nginx/error.log \ 6 --http-log-path=/var/log/nginx/access.log \ 7 --with-http_ssl_module \ 8 --http-client-body-temp-path=/tmp/nginx_client \ 9 --http-proxy-temp-path=/tmp/nginx_proxy \ 10 --http-fastcgi-temp-path=/tmp/nginx_fastcgi 11 $ make 12 $ sudo make install
Run the install script
1 cd /usr/local/src 2 3 wget http://sysoev.ru/nginx/nginx-0.5.35.tar.gz 4 5 tar zxvf nginx-0.5.35 6 7 cd nginx-0.5.35
Create an nginx user and group
1 $ useradd -g www-data -d /var/www nginx
Create the web server directory
1 mkdir /var/www 2 chown root.www-data /var/www 3 chmod ug=rwx,o= /var/www
Test configuration
1 nginx -t 2 2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf syntax is ok 3 2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf was tested successfully
Start nginx
1 nginx
Check if a file or directory exists with bash
This script tests if nginx exists and is executable. The script prints a warning and exits, if nginx doesn’t exists or isn’t executable:
1 DAEMON=/usr/local/sbin/nbinx 2 if [ ! -x $DAEMON ] 3 then 4 echo "Couldn't find $DAEMON. Please set path to DAEMON." 5 exit 0 6 fi
See man test for more information on how to use the test command.
Custom kernel for Debian Etch
Sometimes you just need a kernel that is newer than the package manager has to offer. For me it was the bug fixes for the driver of the sound card in x61s. Here’s how to do it “the debian way”.
1 wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.1.tar.bz2 2 tar xjvf linux-2.6.23.1.tar.bz2 -C /usr/src 3 rm /usr/src/linux && ln -s /usr/src/linux-2.6.23.1 /usr/src/linux 4 cd /usr/src/linux 5 zcat /proc/config.gz > .config 6 make xconfig
Now turn on and configure the new features you are looking for in the new kernel, save the configuration and finally quit.
1 make-kpkg clean 2 fakeroot make-kpkg --initrd --append-to-version=-custom-13.10.2007 kernel_image kernel_headers 3 cd .. 4 sudo dpkg -i linux-image-2.6.23.1-custom-13.10.2007_2.6.23.1-custom-13.10.2007-10.00.Custom_amd64.deb 5 sudo dpkg -i linux-headers-2.6.23.1-custom-13.10.2007_2.6.23.1-custom-13.10.2007-10.00.Custom_amd64.debThe—append-to-version parameter appends the given value into the kernel signature, so that it is easily recognized. If you compile a kernel with the exactly same name as a previous kernel you have then you must move away the directory /lib/modules/your-kernel-name-here.
Fix for "Failed to find an unused loop device" when using xen
If you use Xen and get an error “Failed to find an unused loop device” when you try to create a guest then you are probably using disk images and have run out of loop devices. Each guest uses at least two loop devices. Modify (or create) a file called /etc/modprobe.d/local-loop and add this line:
1 options loop max_loop=64
Use a number suitable for your needs. With 64 loop devices you can run up to 32 guests on your host, assuming you aren’t using loop devices for any other purposes.
Creating a local Debian mirror for your Xen servers
Once you’ve bought a dual or quad Xeon and started to experiment with virtualization you will soon want to create your local mirror to make installs lightning fast. This is a step-by-step how i did it.
First create the Xen that will be our mirror server. The size requirements can be found here: Debian mirror sizes The combined size of amd64 architecture and architecture independent files was 39Gb on 1.9.2007. So I made the image 50Gb big. Remember to change this mirror to a location near you.
1 xen-create-image --hostname=mirrors.aktagon.com \ 2 --size=50Gb --swap=256Mb --ip=10.0.0.44 \ 3 --netmask=255.255.255.0 --gateway=10.0.0.2 \ 4 --force --dir=/work/vserver --memory=256Mb \ 5 --arch=amd64 \ 6 --kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \ 7 --debootstrap --dist=etch \ 8 --mirror= http://ftp.fi.debian.org/debian/\ 9 --passwd
Then ssh into your new Xen as root.
1 ssh -l root mirrors.aktagon.com
Make base configurations for a fresh Xen.
1 apt-get update && apt-get install locales console-data && dpkg-reconfigure locales
Then get the mirror synchronization script from Debian.
1 wget "http://www.debian.org/mirror/anonftpsync" 2 chmod a+x anonftpsync
Then install dependencies for anonftpsync script. Otherwise the script will fail with a -bash: lockfile: command not found error.
1 apt-get install procmail
Install nginx.
1 apt-get install nginx
Configure anonftpsync with your favorite editor and change the lines below. These settings will setup a mirror only for amd64 files. You could remove i386 from the excluded architectures, but then a 50Gb image won’t fit all the files.
1 TO=/var/www/debian 2 RSYNC_HOST=ftp.fi.debian.org 3 RSYNC_DIR=debian 4 LOGDIR=/var/log/mirroring 5 ARCH_EXCLUDE="alpha arm hppa hurd-i386 i386 ia64 m68k mipsel mips powerpc s390 sh sparc source"
Make the log directory.
1 mkdir -p /var/log/mirroring
Configure nginx by modifying /etc/nginx/nginx.conf with your favorite editor. Just add the autoindex line into server { location / { context
1 # abbreviated start of file for clarity... 2 server { 3 listen 80; 4 server_name localhost; 5 6 access_log /var/log/nginx/localhost.access.log; 7 8 location / { 9 root /var/www; 10 # add the line below to allow directory listing 11 autoindex on; 12 index index.html index.htm; 13 } 14 # abbreviated end of file for clarity...
Do the synchronizing. And wait… for a long while. On a 8/1Mbit cable the first synchronize took roughly 20 hours.
1 ./anonftpsync
Now modify your /etc/apt/sources.list on existing Xen images to use your local mirror. And remember to create new Xen images using your new mirror :) In the above case the URL is http://mirrors.aktagon.com/debian
NB: there is no public mirrors.aktagon.com available… sorry.