Philderbeast.com
Where Insanity Thrives… Still

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/nginx.pid;
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_pass 127.0.0.1:9000;
            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/www.philderbeast.com/html/ 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 FrederikM.de
BlueMod is a modification of the blueblog_DE Theme by Oliver Wunder