How to install Jekyll + nginx + Ubuntu + subdomain of godday

I used the following for : blog.algorithmninja.com

Let’s say you have a site www.example.com hosted in aws EC2 with IP: exampleIP


 

For Goddady stuff go here  and following values.

  • Host – blog
  • Points to – exampleIP or the new IP
  • TTL – 600

 

Ngnix Conf:

Write the following conf to /etc/nginx/sites-enabled/example_blog_conf

server { 
 listen 0.0.0.0:80;

 server_name blog.example.com;

 access_log /var/log/nginx/blog.example.log;

 location / {
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header HOST $http_host;
 proxy_set_header X-NginX-Proxy true;

 proxy_pass http://127.0.0.1:4000;
 proxy_redirect off;
 }
}
$ sudo service nginx restart

Jekyll setup

$jekyll new blog
$ sudo apt-get install ruby-full
$ curl -sSL https://get.rvm.io | bash -s stable --ruby
$ source /home/ubuntu/.rvm/scripts/rvm
$ rvm install ruby --latest
$ rvm use ruby --latest
$ gem install jekyll bundler
$ jekyll new blog
$ bundle install

 

Update: blog/_config.yml

title:Example
email: your-email@example.com
description: > # this means to ignore newlines until "baseurl:"
 I have an awesome new Example blog
baseurl: "" # the subpath of your site, e.g. /blog
url: "http://blog.example.com" 
twitter_username: jekyllrb
github_username: jekyll
# Build settings
markdown: kramdown
theme: minima
gems:
 - jekyll-feed
exclude:
 - Gemfile
 - Gemfile.lock
~
$ jekyll serve

..

Boto3: Upload a file to s3

Create an IAM role for s3 and attach the role to the EC2 instance.

import boto3
import sys
import os
from datetime import datetime
import traceback

bucket_name = 'some-bucket'
file_to_upload = "/path/to/file"
file_name = 'file'

try :
  s3 = boto3.resource('s3')
  bucket = s3.Bucket(bucket_name)
  bucket.upload_file(file_to_upload, file_name)
  print( "{} copied to {}".format( file_to_upload, bucket ) )
except Exception as err:
  traceback.print_exc()
finally:
  # time is always in GMT 
  print (datetime.now().strftime('%Y-%m-%d %H:%M:%S'))