You’ve built your app. Now it needs a home on the internet. In this episode we set up an AWS Lightsail server from scratch, step by step. If you’ve never touched a cloud server before, this one is for you.
- An Ubuntu server running on AWS Lightsail
- An SSH key pair to log in with
- A static IP address that never changes
- Firewall rules for SSH and the web (HTTP / HTTPS)
How it all fits together
Your code goes from your laptop to a Lightsail server. On that server, nginx receives visitors’ requests and serves your website. This episode builds the server. The next ones put nginx and your site on it.
Create the instance and choose a region
In the Lightsail console, click Create instance. Pick the region closest to your visitors; we use Mumbai. A nearer region means faster page loads for your audience.
Pick the operating system: Ubuntu
Choose Linux/Unix, then OS Only, then Ubuntu. Every command in this series is written for Ubuntu.
Choose a plan
The small plans are enough for a website like ours. In the video we explain the $5 plan: what you get in memory, CPU, storage and data transfer, and why it is a good starting point. You can move to a bigger plan later.
Name the instance and download the SSH key pair
Give the instance a clear name. Then create and download an SSH key pair: a .pem file that works like the key to your server. Keep it safe and never share it. You’ll use it in the next episode to log in from your own computer.
Launch the instance
Click Create instance. After a minute or so its state changes to Running.
Attach a static IP
By default the server’s public IP can change when the instance stops and starts, which would break your domain’s DNS record. Under Networking, create a static IP and attach it to the instance. This is the address your domain’s A record points to.
Connection details
The instance page shows the user name (ubuntu) and the public IP. With your downloaded key, logging in from a terminal looks like this:
ssh -i /path/to/key.pem ubuntu@YOUR_SERVER_IP
If this complains about the key, don’t worry: episode 3.1 covers that exact error and the fix.
Firewall rules
Under Networking → IPv4 firewall, make sure these are allowed:
| Application | Port | Why |
|---|---|---|
| SSH | 22 | So you can log in |
| HTTP | 80 | Normal web traffic |
| HTTPS | 443 | Secure web traffic, once you add SSL |
Open only what you need. Every extra open port is one more door to the server.
If it doesn’t work
The site or SSH stopped working after a restart. Without a static IP, the public address changes when the instance restarts. Attach a static IP and update your DNS record to it.
The browser can’t reach the server. Check the Lightsail firewall: port 80 (and 443 for HTTPS) must be allowed, and something like nginx must actually be running on the server.
Next
The server is running. Next we log in to it properly: SSH from the browser and from your own computer, with your own key.
