Static website

Nginx

So you want to host a little static website on your VPS, or at least try to? LES is ideal for that. And to do that, you will need some kind of web server. As the amount of RAM is not in GBs but rather MBs we will use Nginx, not Apache or others. Why? Search.

Nginx is available in Debian repositories, but we will use packages from Nginx team. As website says: "Most Linux distributions and BSD variants have Nginx in the usual package repositories and they can be installed via whatever method is normally used to install software (apt-get on Debian, emerge on Gentoo, ports on FreeBSD, etc). Be aware that these packages are often somewhat out-of-date. If you want the latest features and bugfixes, it's recommended to build from source or use packages directly from nginx.org. "

Install nginx

To do that, few steps are required.

sudo touch /etc/apt/sources.list.d/nginx.list

Now edit this newly created file to looks like this:

deb http://nginx.org/packages/debian/ squeeze nginx

deb-src http://nginx.org/packages/debian/ squeeze nginx

This way you told your Debian to use this repo. But to be sure we have what we wanna have, you need to add key for this repo. Type following.

wget http://nginx.org/keys/nginx_signing.key

cat nginx_signing.key | sudo apt-key add -

Now we can install nginx like we did before when installing sudo. You should remember that.

Don't forget to run apt-get update, otherwise you wont be able to install nginx

Please make sure, that you installed version from official nginx repo. You can do it by typing following.

sudo apt-cache policy nginx

Output should be similar to this one.

nginx:

Installed: 1.4.3-1~squeeze

Candidate: 1.4.3-1~squeeze

Version table:

*** 1.4.3-1~squeeze 0

500 http://nginx.org/packages/debian/ squeeze/nginx i386 Packages

100 /var/lib/dpkg/status

0.7.67-3+squeeze3 0

500 http://ftp.nl.debian.org/debian/ squeeze/main i386 Packages

500 http://security.debian.org/ squeeze/updates/main i386 Packages

As you can see, installed version from official nginx is 1.4.3. Debian repo has version 0.7.67. Another reason for using official repo is support - it will be easier to get it in case you run into troubles. Debian version is probably a bit different from official one, thought it's not that simple.

Configuring nginx

Let's configure nginx so we can use it to serve people our simple website. We will use following file, so go ahead and open it with your favourite editor.

/etc/nginx/conf.d/default.conf

First thing we need to do is change Listen part. There is number 80, but it should looks like this:

listen [one-of-your-ipV6-addresses]:80 default ipv6only=on;

What we did here made server work with one of your IPv6 address and with port 80. And it will use only IPv6. Unfortunately the most people still use IPv4, but we will deal with it later.

Around line 9 you should see "root /usr/share/nginx/html". That's the folder where we will put our html files. You can keep it, or you can change it. I myself changed it to "/var/www". Folder does not exist yet, so let's create it. We will also change our user and folder so that we can put and edit files there without need to use sudo all the time.

sudo mkdir /var/www

sudo adduser username www-data

sudo chown -R www-data:www-data /var/www

sudo chmod -R g+rw /var/www

And to make changes we made in config file to take effect, let's restart nginx.

sudo /etc/init.d/nginx restart

Testing nginx

Your server should be reachable now. If you use IPv6, you can type your address in browser, if not use IPv6 proxy. Here is example for you.

http://[2001:420:80:1::5]

As you probably have not put any files on your server yet, you might see and 404 error. Following is 404 from IPv6 proxy website.

The requested resource could not be loaded because the server returned an error: 403 Forbidden (?).

Copy files to server

We can do it easy with SCP (or WinSCP for Windows). Syntax is similar as with SSH.

scp -P YYYYY page.html [email protected]:/var/www

IPv4 connectivity

Opposite of IPv6, we ain't got any IPv4 addresses. There are more ways how to be reachable with IPv4 (search forums) and it's up to you what suits you better. I will not make any recommendations, I will only say which solution I use.