How to install your own git server?

Because i use jigsaw for this blog, i want to share with you how i setup the deployment of my blog.

The problem with the static site is, we does not have an editor that we can use on the fly. Like wordpress for example they have admin dashboard we can compose out blog post from the admin and click button publish when we are ready.

Using git for static site is perfect and i think it is really easy. So this is the step by step how i setup git server for this blog. Server

This blog post i post to my $5 private server on vultr. And i have full control over my server. So this is how i setup my application.


The first one will always to install a git. By the way i use ubuntu on my server.

sudo apt install git

Add git user

And then next add new git user on my server.

sudo adduser git

And then create ssh folder.

su git
mkdir .ssh
touch .ssh/authorized_keys

And then go to local computer and copy public ssh keys.

cat .ssh/

Then paste into the .ssh/authorized_keys.

And now let's verify if the configuration was running successfully.


Create Repository

Now we already completed server configuration let's create the repository.

mkdir blog.git
cd blog.git
git init --bare

And one more thing we need to create hooks to extract the file from the git repository in our server. Save into hooks/post-receive.

git --work-tree=/var/www/blog --git-dir=/home/git/blog.git checkout -f master

And make it executable.

chmod +x hooks/post-receive

Add remote deploy to local.

git remote add deploy

And then just push the code.

git push deploy

Nginx Configuration

One last thing we need to config static server configuration. The config it's really simple. Just create file /etc/nginx/config/blog.conf.

And the config is look like this.

server {
        listen 80;
        root /var/www/blog/public;
        index index.html;

And then activate the server.

sudo nginx -s reload

Make it https

And this is also important don't forget to make it secure with ssl. Luckily it so easy to install ssl to nginx server.

Let's install certbot.

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx -y

And then install the ssl.

sudo certbot --nginx -d

This is will need you to add your email and agreement. After that we are done.