VPS Notes

Beginner Tutorial – Installing Webserver and Setup a Static Website

Installing and configuring a website is not difficult. But to further reduce the steps and see something working right away, we will start first with setting up a static website.

Clean UP

First, let's clean up our vps. Update our packages from the distribution repositories and install the latest versions of the programs we already have.

$ apt-get -y update
$ apt-get -q -y upgrade

Templates from VPS providers usually have some programs installed that we don't need. Let's remove them.

$ apt-get -q -y remove --purge portmap apache2* bind9 samba* nscd sendmail* whoopsie*
$ apt-get -q -y autoremove

Let's install some useful programs

$ apt-get -y install locate nano htop less zip gzip unzip less git-core

Install NGINX

NGINX is my recommended web server. It uses minimal RAM and CPU and easy to install and configure.

Install NGINX

$ apt-get -y install nginx

Make the number of child process to be the same as the number of CPU cores available for you:

$ sed -i "/worker_processes/cworker_processes `nproc`;"  /etc/nginx/nginx.conf

Remove the default website configuration

$ rm /etc/nginx/sites-available/default

Setup Static Website

Create /var/www where we will place all website we will host

$ mkdir /var/www

Create /var/www/vpsnotes.com to host our website.

$ mkdir -p /var/www/vpsnotes.com

Create content page index.html

$ echo "<html><title>My Website</title><body><h1>My Website</h1>Welcome it works</body></html>" > /var/www/vpsnotes.com/index.html

Configure NGINX for our website. Create the config file: /etc/nginx/sites-enabled/vpsnotes.conf

$ nano /etc/nginx/sites-enabled/vpsnotes.conf

And use the following contents:

server {
    listen 80;
    server_name vpsnotes.com www.vpsnotes.com;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/www/vpsnotes.com;

Restart NGINX so that the config will take effect:

$ service nginx restart

Now assuming you have configured your domain/dns to point to your server, you can hit your browser to visit the page:


A script is prepared to shorten the steps above. First download the script:

$ wget https://raw2.github.com/vpsnotes/setup/master/setup.sh

Clean UP and install NGINX

$ bash setup.sh init
$ bash setup.sh install_nginx

Install a static website

$ bash setup.sh add_static_website vpsnotes.com

Restart NGINX

$ service nginx restart

Tags: nginx, static, web server