Project 7: Configure web server

7 May 2019   PDF version

For this project, you should configure your virtual private server (from Check-in 11) to deploy a static web site.

  • It should support SSL/TLS (accessible over https), and the plain unencrypted site (at http) should redirect to the encrypted version.
  • You should implement a workflow for conveniently updating the site’s content via git – this could be by logging into the server and doing git pull, or setting up a repository on your server with a git hook so you can instead do git push from a development machine.

Hint: code to add to your VirtualHost block to force redirect (change HOST to your host name):

RewriteEngine on
RewriteCond %{SERVER_NAME} =HOST.liucs.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Hint: here are rough instructions for a git push workflow to your server. On the server, first go to your host’s folder in the Apache www folder, and then create a bare git repository beside it:

cd /var/www/HOST.liucs.net
mkdir html.git
cd html.git
git init --bare

Create a “post-receive” hook script, as follows:

touch hooks/post-receive
chmod +x hooks/post-receive
nano hooks/post-receive

Now you will be in the editor for your script. Enter and save the following code:

#!/bin/sh
export GIT_WORK_TREE=/var/www/HOST.liucs.net/html
git clean -fd
git checkout -f

Your repository is currently empty, so commit the existing html directory to it:

git --work-tree=../html add .
git --work-tree=../html commit -m "Initial commit"

Your workflow is now steps away! Clone the server’s repository into your local development environment like this:

git clone root@HOST.liucs.net:/var/www/HOST.liucs.net/html.git
cd html

Now you can edit the files, and use add/stage/commit as normal. When you push back to origin, the files should “go live” on your server!

Be careful though – if you make any manual edits to the html directory on the server, those would be overwritten on the next push!