Where Insanity Thrives… Still

With my previous post regarding setting up a web server another item that should be on your agender if your setting up this sort of software would be an authoritive name server to serve out your DNS records for the domains you plan on serving out.

unfortunatly in my browsing i have been unable to find as nice a solution as I did for nginx to serve out a large number of domains. but what i did find was a dns server called maraDNS, the little cousin to BIND. This allows me to run an authoritative name server using less then 200kB of RAM!

# The address this DNS server runs on.  If you want to bind
# to all addresses a given machine has, use "".
bind_address = ", 111.222.333.444"
# The directory with all of the zone files
chroot_dir = "/etc/maradns"
# The numeric UID MaraDNS will run as
maradns_uid = 105
# The (optional) numeric GID MaraDNS will run as
maradns_gid = 109
# The maximum number of threads (or processes, with the zone server)
# MaraDNS is allowed to run
maxprocs = 96
# we are the authority on all under here!
csv2 = {}
csv2[""]       =  ""

by any stretch this config file is very simple binding the server to (to allow the use of the Askmara tool to check configuration) ONE of the servers external IP addresses and lastly we give a list of the domain that mara will serve for us.

there is only one peice of magic i have found with mara and that is in th zone config files that i have written like the following:

#give authority information
Issuing NS           | Contact email              | Serial No | Refresh [1h] | retry [10m] | expire [1d] | min ttl [1h]
% soa            1            3600           600           86400         3600
% ns
% ns
#main web ip
% a
ftp.% cname %
www.% cname %
#mail server
% mx 0 mail.%
mail.% a

This allows this zone file to be used for ANY domain the server will send out using these basic records so you only need to make a unique file if you have unique dns entry’s (extra subdomains etc) this is able to be done since maraDNS parses % as the zone being served set in the main config file.

and that’s all I really have to say on that count. Again another peice of software helping to bring you this page explained.

Well so as not to leave this to long I thought I would start with how I went about setting up Nginx (the software that is serving you this page)

My configuration is designed to allow me to easily add extra domains on as virtual hosts without having to change the server config files. while also giving me the flexibility to add new services on other ports (like web mail) with a minimum of fuss.

I won’t go in to the specifics of installing Nginx as im sure you will find that on a million other blog posts or your chosen distribution’s documentation.

after installing and checking that Nginx will serve web pages the first step is to make a few changes to the way that Nginx handles files, particularly if you want to serve PHP files with it.

so lets take a look at my nginx.conf file:

user www-data;
worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /var/run/;
events {
    worker_connections  1024;
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    keepalive_timeout  65;
    tcp_nodelay        on;
    gzip  off;
    server_name_in_redirect off;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        server_name _;
        root /var/www/$host/html/;

        allow all;
        location / {
            index index.php index.html index.htm;
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|htm)$ {
            access_log off;
            expires 30d;
        location ~ .php$ {
            fastcgi_index index.php;
            include fastcgi_params;
       location ~ /\.ht {
           deny  all;

    include /etc/nginx/ports/*.conf;

As you can see I am only starting 1 worker process, meaning only one page will be served at a time, this is fine for a small traffic site, but if it starts to get more traffic then I would need to increase this number to improve the response time of the server. we then set the server wide defaults, with the error log file and how many connections the worker will take before it refreshes.

Then we go in to the magic section of the file that allows all our virtual hosts to work.

This server directive listens on port 80 and will accept connections with any server name (i.e. domain name) it will then set the root directory to a directory specified by the host name that is sent with the request so for this site it is set to /var/www/ we then give the index files, in this case html files and php files, and lastly the location directives, working from last to first (the way the priority for NginX works, .htaccess files are not allowed to be viewed over this connections, php files are parsed by extension (I’m yet to find a better way to do this) to the fastCGI server listening on port 9000 and all its parameters are set in the fastcfi_params file (this file will be explained in a later post) then all static files (images and html files) are sent directly and not logged in the access log.

Then once that default port 80 server is define we include all files in the ports directory that i created where i have a set of config files that define the different applications that run on other ports (web mail etc)

This config allows me to add a new domain by simply pointing its DNS records to the server and creating a directory in /var/www/ to hold its web files, I don’t have to restart NginX, change config files etc. making it quite useful in a number of situations including if you wanted to host a number of other domains that arnt yours (say your a hosting company) and a huge advantage over apache it only uses less than 2Mb of memory per worker process, and this does NOT grow depending on how much traffic you are getting, so start your server, check your memory usage, and you know that it will sit at that level and not drop into paging hell should you, or another site on the server be luck enough to experience the /. effect.

Tags: , , , ,

Well its been far to long since I put something on here… mainly due to a lot of other things being worked on in the background.

After coming back and getting out of the routine of being at sea and having a whole house to look after again. It’s been nice to settle down for Christmas and spend some time with family.

But more importantly it has let me do some more work on doing a few changes to this site (that you haven’t seen), after a bit of Google searching i came across lowendbox and was reading not only about cheap deals on servers but also on how much a very small server could run, and after my own previous experiments with a Pentium 233mhz computer with 32mbs of ram I thought it would be interesting to see what I could do in a memory limited environment with this site and all the things I want to swing off it.

The result was the current location of my website, no longer hosted in Melbourne but the USA, on a 128mb RAM Xen VPS from quickweb that I got on special for half price, making it an even better deal 🙂

So after a couple of weeks of tweaking i have got it all setup and running with almost everything i wanted out of the servers with only 100MB of RAM used under load (not much load but what this site produces) after a few changes in the software stack (mainly removing Apache in favor of Nginx) and some configuration changes (particularly MySql) to help lower the memory foot print. to keep it from swapping constantly i have a full fledged web server with php and mysql, mail server and SVN server running so far. next stop the DNS cluster to move away from Cpanel hosting entirely.

now i must say that if you are looking to host a largish site or many sites looking in to a small VPS is defiantly a consideration you should think of, most hosts have images will all the software already installed to host your site (unless you go for something out of the ordinary) and they can handle a surprising ly large amount of traffic easily, and not to mention Google will help you solve most of your hosting problems on there.

My next project will be a small lightweight control panel to help administer this beast 🙂 (hence the SVN server)

So I should be posting some more on here as I get that up and running with how I have been getting it all to work, and small howto’s on getting your own full featured webserver running on a cheap VPS.

Tags: , , , , , ,

Powered by Wordpress
Theme © 2005 - 2009
BlueMod is a modification of the blueblog_DE Theme by Oliver Wunder