Welcome

Welcome to my portfolio website. I built it because most of my work has been in databases and data analysis, but I wanted to be able to show what I can do outside that area. The site is hosted on Amazon Lightsail Cloud Server running Ubuntu. Ubuntu is running MariaDB, Nginx, Gunicorn, and Django (Python).

Let me walk you through this diagram of, generally, how this website is put together. In the top right is your browser heading to ndwalker.com. This hits a DNS (Domain Name Server), which translates ndwalker.com into the correct IP address: 3.22.4.96. Going to this IP address brings you to my site, which is located inside AWS. Amazon forwards the traffic to the internal IP address of my EC2 instance, where Nginx picks up the request. Nginx redirects all http traffic to https, which adds encryption. It then looks at the URL requested to see if it's a static or dynamic file. If it includes .com/static/... it finds the file in the static folder and returns it directly to you. Otherwise it sends the dynamic request to the Gunicorn. Gunicorn has three instances of Python each running the same Django web app and it forwards the request to one of them. Django matches the requested URL to a specific endpoint (like /website/ or /projects/) and runs the corresponding class' .get() or .post() method, depending on the type of request. If required, Django connects to the MariaDB database and gets, inserts, updates, or deletes data. At the end, Django likely returns HTML to your browser, which displays this site.

See below for more details about most of these steps.

Amazon Lightsail

Amazon Lightsail is a virtual server that allows you to quickly, easily, and cheaply stand up a web service. Out of the box, it lets you choose your operating system (Linux or Windows) and has pre-made setups for multiple use cases: WordPress, GitLab, Django, Nginx, Node.js, and more. Unfortunately, the version of Django available didn't match my dev environment, so I had to choose a clean Ubuntu install and set everything up myself instead. In addition to a virtual server (what amounts to an EC2 instance), Lightsail also takes care of basic networking, user access, and backup. Cost is based on system capabilities and storage size plus your average CPU usage (like other EC2 instances). This last bit means that if my CPU usage goes over 10% for any length of time, I lose "burst" credits. They "recharge" over time, but if they run out, the instance throttles performance.

Ubuntu

Ubuntu is a popular Linux distribution. I chose it because of the two options Lightsail offers (Linux and Windows), I didn't want to incur the extra cost of Windows and I'm already familiar with Ubuntu, since it's what I use in my local WSL2 instance.

Setting up the Ubuntu instance was straightforward: install all the things and make sure they run at startup. As a first venture, I feel good about having taken this route because it allowed me to troubleshoot the issues concretely. It was similar enough to my development environment that I had a good idea of what I was trying to accomplish and how to do it. In the future, however, I will definitely use a container service. As I set up my Ubuntu server, I took notes for Future Nathan and was surprised just how taxing the process was now that I've been so spoiled by Docker. Now that I have all the steps to get from a fresh Ubuntu install to a working server, I can write up a Dockerfile with little trouble. That sounds like a good blog idea...

Nginx

Nginx is an open source web server similar to Apache HTTP Server. All web traffic pointed at my public IP address goes through Nginx first. Broadly, Nginx controls who gets to access the site and handles a layer of security. It stops bad requests that come to the wrong port or from a blacklisted IP address. If the request comes in as HTTP, it forwards it to the HTTPS endpoint and handles the TLS handshake. If the URL begins with "ndwalker.com/static/", the resource is fetched and returned immediately. If it's anything other than "/static/" the request gets forwarded to Gunicorn.

Gunicorn

Gunicorn is a WSGI HTTP Server. It spins up multiple (in my case: 3) instances of Django and sends requests to one of the instances. If one of the instances takes too long to respond, it restarts it. All access and error logs get stored locally, so that's one less thing to have to configure manually.

Django

Django is a web framework written in Python, similar to Flask. I had worked with Flask in the past, but wanted something opinionated with built-in security and user administration options, so Django seemed like the best choice. When a request makes it to Django, if the URL matches a predefined pattern, a View handles the request. The View looks at the type of request (GET, POST, etc.) and runs the corresponding function, which could hit the database and generate some content, then returns it to the user in some format. Likely that format is HTML based on a Template file. Django uses Jinja2 to allow you to generate HTML on the fly. So instead of needing to specify all the HTML needed to display a list of items, Django allows you to create a shell and fill in the items in the list without worrying about how many there are. Similarly, Django allows you to specify the contents of a form in Python and then it handles creating the HTML and facilitates database read/writes. Super slick.

MariaDB

MariaDB is an open source version of MySQL, a popular database engine. I chose it because it's free, familiar, and accomplishes all the things I need it to. I also already had a Docker Compose file ready to go for local development, so it was an easy decision. MariaDB houses all of the Django user and admin data plus all app-specific data like blog posts and Twitter user information.

© Nathan D Walker. All rights reserved.