Sep 2, 2019
This site is powered by Hugo, served by Apache. I moved away from WordPress because it’s too heavy for a personal site. It’s also slow and I could not find a theme that suits the purpose of the site. So, eventually I’m with Hugo and using markdown for everything.
The setup is very simple:
- Download Hugo from GitHub. Note that we need the extended version.
$ wget https://github.com/gohugoio/hugo/releases/download/v0.55.5/hugo_extended_0.55.5_Linux-64bit.deb
- Extract the downloaded pacakge.
$ sudo dpkg -i hugo_extended_0.55.5_Linux-64bit.deb
The theme I use is hugo-book. It’s built for documentation but I find it also works great for me.
SSL is enabled through Let’s Encrypt.
AWS EC2 Setup
The graph below describes the overall structure of my EC2, running an Ubuntu 16.04 Bitnami WordPress stack. I still have WordPress running for some other domains, but mingze-gao.com is static and directly served by Apache. I use Apache to redirect adrian-gao.com to mingze-gao.com as well.
Since some apps (e.g. LeGao - Make LEGO Pixel Art) need to communicate with my server, I re-write the backend as shown above.
In the past, I had separate Flask apps listening 0.0.0.0 on ports 5000, 5001, etc., and opened these ports on the AWS Security Group. It worked but apparently was not ideal. First, it is risky that additional ports were open. Second, sometimes results were blocked by certain browser as they were not returned through usual ports.
Therefore, I’ve moved everything behind a unified gateway api.adrian-gao.com. I use Apache to reverse proxy all requests to
api_server.py that redistributes them according to the request url. Itself is a very simple script, the core logic is just to use
requests.request to forward the request to the responsible app according to the port mapping dictionary.
As such, each app is completely separated from others. All requests starting with
/legao go to
/legao/server.py and those starting with
/optimization go to
One problem with this setup is that the headers from
/optimization/server.py, etc. will be overwritten by Apache. So I need to set Access-Control-Allow-Origin and Access-Control-Allow-Headers in the Apache config file, which looks like this.
Then everything is good to go 😎