Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

How to Host a GitHub Website on AWS EC2 with Nginx

Real projects aren't typed into nano: developers keep their code on GitHub, and our job as cloud engineers is to host it. In this chapter we find a free static website on GitHub, bring it onto an EC2 server with wget, unzip it, and point Nginx's root at the right folder. On the way we fix the key-permission error that stops ssh, learn to find the folder that really holds index.html, and see why several sites on one server need domain names. We finish with a warning about phishing pages, because the same hosting skill is what attackers misuse.

In this class

  • What GitHub, a repository, public and private repos, and organisation accounts are
  • How to tell a static project from one that needs a backend, using the language bar
  • Fixing UNPROTECTED PRIVATE KEY FILE on Linux, Mac and Windows
  • Two ways to get a repository onto the server: Download ZIP + scp, or wget on the server
  • Example 1: a repo with ten sites, hosted from /usr/share/nginx/tensites
  • Example 2: a repo with dozens of mini-projects: find index.html, run pwd, set root
  • Opening several projects by folder name, and why domains are the proper way
  • Safe habits: pwd before rm -rf *, quotes around odd URLs, file.zip.1, checking the LICENSE
  • How phishing login pages steal passwords, and how to protect yourself

1. Why: real projects live on GitHub

In the last chapters we wrote pages by hand or let an agent write them. In real companies, code lives in one place where the whole team works on it, and very often that place is GitHub. Developers write the code; we host it.

Classroom line

We keep our code stored on github.com.

2. What: GitHub and repositories

Before you host a company's code you must know where it lives and whether you are allowed to download it. Public and private repositories answer that question.

GitHub (github.com, owned by Microsoft) is a website where companies and developers store source code. One project's code store is a repository, or repo.

  1. A public repository can be seen and downloaded by anyone on the internet. You don't need to sign in to search or download public repos.
  2. A private repository is visible only to the people you allow. They sign in, or use a token.
  3. Free accounts can have unlimited public and private repositories.
  4. Companies keep their repositories in organisation accounts that the whole team shares.

Classroom line

A public repository means anyone in the world can download that code from the internet.

GitHub: where projects keep their code github.com Companies and developers store source code here. One project = one repository (repo). Public repository Anyone on the internet can see and download it. No sign-inneeded. Private repository Only the people you allow. They sign in or use a token. Free accounts can have unlimited public and privaterepositories. Companies keep their repos in organisation accounts,shared by their team.

Figure 1. One project is one repository. Public: anyone can download. Private: only people you allow.

Static or backend? Read the language bar. Every repository page shows a coloured bar with the languages it uses.

  1. Only HTML, CSS and JavaScript: a static site. Nginx serves the files as they are. That's what we host in this chapter.
  2. Java, Python, PHP or other languages: the project needs a backend that runs code. Copying the files isn't enough; we host those later in the course.
Read the language bar before youdownload Only HTML, CSS, JavaScript A static site: plain files. Nginx serves them as they are. This is what we host in this chapter. Java, Python, PHP and others Needs a backend that runs code. Copying the files is not enough; we host these later in the course.

Figure 2. HTML, CSS and JavaScript only: static, Nginx serves it. Java, Python or PHP: needs a backend.

Example 1: searching. On github.com, search for html websites. You'll find repositories that hold one site, and some that hold dozens of small beginner projects. If you click through search pages very fast while signed out, GitHub shows a Too many requests page. Wait a minute, or sign in.

3. How: connect to the server

Nothing in this chapter works until you are on the server. The key permission fix here is the one Mac, Linux and newer Windows users hit first.

Step 1. Launch an Amazon Linux server (or reuse one) with SSH and HTTP allowed. Use free-tier eligible instance types, and check AWS's current free-tier terms.

Step 2. Check the AMI to pick the username: ec2-user for Amazon Linux, ubuntu for Ubuntu.

Step 3. Connect:

ssh -i mykey.pem ec2-user@PUBLIC_IP

If ssh refuses the key. You may see:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'mykey.pem' are too open.
...
ec2-user@PUBLIC_IP: Permission denied (publickey).

A private key is like a house key. If other users on your computer can read the file, ssh refuses to use it. The file must be readable only by you.

Classroom line

The PEM file needs only 400 permission.

Fix on Linux and Mac.

Step 1. Run:

chmod 400 mykey.pem

400 means: 4 = read for you (the owner), 0 = nothing for the group, 0 = nothing for everyone else.

Fix on Windows. In PowerShell, cd and ls work because PowerShell has its own commands with those names, and ssh and scp work because Windows includes the OpenSSH client. chmod isn't there, so use the file's Properties. Earlier Windows versions let the key through; newer updates are strict too.

Classroom line

In Windows we could ssh directly. Now Windows too is slowly making this compulsory in the new updates.

Step 1. Right-click mykey.pem and choose Properties, then the Security tab, then Advanced.

Step 2. Click Disable inheritance and choose Remove all inherited permissions. Inheritance means the file got its permissions from its parent folder.

Classroom line

What is inheritance? We call it 'varasa' (what's handed down).

Step 3. Click Add, then Select a principal, type your Windows user name, click Check Names and OK.

Step 4. Tick only Read, then OK and Apply. Now only you can read the key, and ssh accepts it.

The key file must be readable only by you WARNING: UNPROTECTED PRIVATE KEY FILE! ec2-user@PUBLIC_IP: Permission denied(publickey). Linux and Mac chmod 400 mykey.pem 4 = read for you (the owner) 0 = nothing for the group 0 = nothing for everyone else Windows: file Properties 1. Security tab, then Advanced 2. Disable inheritance, remove all inherited 3. Add, then Select a principal: your user 4. Tick only Read, then OK and Apply

Figure 3. ssh refuses a key others can read. Linux and Mac: chmod 400. Windows: Properties, Security, Advanced, only your user with Read.

4. How: two ways to get the code onto the server

Choose a snapshot or a checkout

A Git repository stores a project’s files and its history. A commit names one recorded version. A ZIP download gives you the files from a selected version. A Git checkout also gives you the repository data needed to inspect history and fetch other versions. Keep that checkout in a working folder, as the example below explains.

Try both for a small project you own. In the checkout, run git log -1 --oneline to record the commit you are looking at. In the ZIP copy, check the filename or release notes that identify its version. Before asking which copy is on EC2, make a small visible lab release marker and confirm it at the deployed URL. That is more precise than trusting that the folder name is current.

There is more than one road from GitHub to your server. Knowing both lets you pick the faster one, and fall back to the other when a link doesn't work.

GitHub Code dropdown: Clone section with HTTPS and GitHub CLI tabs, a clone URL https://github.com/OWNER/REPO.git with a copy button, Clone using the web URL, then Open in GitHub Copilot app, Open with GitHub Desktop, and Download ZIP with the mouse pointer on it.

Whiteboard: The green Code button on a repository: the clone URL, and Download ZIP at the bottom. Right-click Download ZIP to copy its link.

Way A: Download ZIP, then scp. Click Code > Download ZIP on your computer, then copy it up:

scp -i mykey.pem main.zip ec2-user@PUBLIC_IP:/home/ec2-user/

The file travels twice: GitHub to your computer, your computer to the server.

Way B: copy the link, wget on the server. Right-click Download ZIP, choose Copy link, and paste it after wget in the server terminal. The server downloads straight from GitHub: faster, and one step less.

Classroom line

Right-click Download ZIP, copy the link... and go to the terminal and paste it after wget.

Two ways to get a repository onto the server A. Download ZIP on your computer, then scp GitHub → Your computer → EC2 scp -i mykey.pem main.zipec2-user@PUBLIC_IP:/home/ec2-user/ The file travels twice: GitHub to your computer, then your computer tothe server. B. Copy the ZIP link, then wget on the server GitHub → EC2 sudo wgethttps://github.com/OWNER/REPO/archive/refs/heads/main.zip The server downloads straight from GitHub. Faster, one step less.

Figure 4. Way A: Download ZIP and scp. Way B: copy the ZIP link and sudo wget on the server.

5. Example 1: one repository with ten sites

A repository with an index.html at its top is the simplest real case: download, unzip, point Nginx at it, done.

What we'll build. A repository holds ten sample sites and an index.html that links to all of them. We put it in /usr/share/nginx/tensites and point Nginx at it.

For your own project, keep the Git checkout outside the web root. Point Nginx at a separate directory containing only the files visitors should open, such as the dist/ output of a frontend build. The checkout contains Git history in .git and may also hold private configuration. Before publishing, list the release directory with ls -la and confirm it contains the site’s build output.

Step 1. Start Nginx (install it first with sudo yum install nginx -y if needed) and see where it serves from now:

sudo service nginx start
cd /usr/share/nginx/html
ls

Step 2. Go one folder up:

cd /usr/share/nginx

Step 3. Download the ZIP. sudo is needed because this folder belongs to root:

sudo wget https://github.com/OWNER/REPO/archive/refs/heads/master.zip

Some repos use main instead of master; copy the link exactly as GitHub gives it.

Step 4. Unzip it:

sudo unzip master.zip

This creates a folder named REPO-master.

Step 5. Give it a short name:

sudo mv REPO-master tensites

Step 6. Check that index.html is right inside:

[ec2-user@ip-172-31-xx-xx nginx]$ cd tensites
[ec2-user@ip-172-31-xx-xx tensites]$ ls
README.md  index.html  style.css  ...  (one folder per site)
[ec2-user@ip-172-31-xx-xx tensites]$ pwd
/usr/share/nginx/tensites

Step 7. Open the settings file:

sudo nano /etc/nginx/nginx.conf

Step 8. Change the root directive in the server block:

root         /usr/share/nginx/tensites;

Save with Ctrl+O, Enter, then Ctrl+X.

Step 9. Apply it:

[ec2-user@ip-172-31-xx-xx tensites]$ sudo service nginx reload
Redirecting to /bin/systemctl reload nginx.service

Step 10. Open http://PUBLIC_IP/. You see the repo's index page; click through to each of the ten sites.

Example 1: from a GitHub ZIP to a live site 1. cd cd /usr/share/nginx Go to the folder next to Nginx default html folder. 2. wget sudo wgethttps://github.com/OWNER/REPO/archive/refs/heads/master.zip Download the ZIP straight from GitHub. sudo, because thefolder belongs to root. 3. unzip sudo unzip master.zip It creates a folder named REPO-master. 4. mv sudo mv REPO-master tensites Rename it to something short. 5. root root /usr/share/nginx/tensites; In nginx.conf, then sudo service nginx reload and openhttp://PUBLIC_IP/.

Figure 5. Animation: cd, sudo wget, sudo unzip, sudo mv to a short name, root in nginx.conf, reload.

Replacing an old site in the html folder instead. If you'd rather unzip inside /usr/share/nginx/html, you may first want to clear the old files with sudo rm -rf *. That deletes everything in the current folder, with no undo. Run pwd first and make sure it prints /usr/share/nginx/html.

6. Example 2: a repository with dozens of mini-projects

Why this is different. Some repositories hold dozens of small projects, each in its own folder. If root points at the top folder of the ZIP, there's no index.html there and the site doesn't show. You have to find the folder that holds index.html.

Classroom line

You must understand folders.

Step 1. Download and unzip it in the html folder:

cd /usr/share/nginx/html
sudo wget https://github.com/OWNER/REPO/archive/refs/heads/main.zip
sudo unzip main.zip
sudo mv REPO-main projects

Step 2. Walk in with cd and ls:

[ec2-user@ip-172-31-xx-xx html]$ cd projects
[ec2-user@ip-172-31-xx-xx projects]$ ls
LICENSE  README.md  projects
[ec2-user@ip-172-31-xx-xx projects]$ cd projects
[ec2-user@ip-172-31-xx-xx projects]$ ls
age-calculator  dad-jokes-generator  music-player  rock-paper-scissors-game  ...

Step 3. Go into one project and check for index.html:

[ec2-user@ip-172-31-xx-xx projects]$ cd music-player
[ec2-user@ip-172-31-xx-xx music-player]$ ls
index.html  script.js  style.css  ...

Step 4. In the folder that shows index.html, run pwd and copy the path:

[ec2-user@ip-172-31-xx-xx music-player]$ pwd
/usr/share/nginx/html/projects/projects/music-player

Classroom line

In the folder that has index.html, simply fire pwd.

Step 5. Paste it as the root setting in /etc/nginx/nginx.conf. Change only this line:

root         /usr/share/nginx/html/projects/projects/music-player;

Step 6. Reload and open http://PUBLIC_IP/. The music player shows.

sudo service nginx reload
Example 2: many projects in one repo. Find thefolder with index.html 1. cd and ls cd projects/projects ; ls Dozens of folders, one per mini-project. No index.html hereyet. 2. index.html? cd music-player ; ls -> index.html script.js style.css This folder has index.html: this is the site. 3. pwd pwd ->/usr/share/nginx/html/projects/projects/music-player pwd prints the full path. Copy it. 4. root, reload root/usr/share/nginx/html/projects/projects/music-player; Paste it as the root setting, save, reload.

Figure 6. Animation: cd and ls until you see index.html, pwd, paste the path as root, reload.

Example 3: switch to another project. Same steps, another folder:

cd ../dad-jokes-generator
pwd
sudo nano /etc/nginx/nginx.conf
sudo service nginx reload

with root /usr/share/nginx/html/projects/projects/dad-jokes-generator;. Changing root switches which one site the server shows.

7. Many projects at once: folder URLs, ports, domains

Use the project type to decide what to publish

If the repository contains a ready-made index.html, CSS and images, a static web server can serve those files. A frontend project may need a build step that converts development files into a browser-ready output folder such as dist/. A backend that must run Python or Node.js needs a running application process. Serving its source folder as static files will not start it.

Read the project README and locate the file the browser is meant to open. Test that output in a lab directory first. If the URL lists files or downloads source, stop and check the document root and application setup. Do not make a full source checkout or private configuration available as page files.

When one repository holds many projects, you must decide how visitors reach each one. Folder URLs, ports and domains are the three options, each with a cost.

Root at the parent folder. Set root to /usr/share/nginx/html/projects/projects;. Now every project opens at its folder name:

  1. http://PUBLIC_IP/music-player/
  2. http://PUBLIC_IP/dad-jokes-generator/
  3. http://PUBLIC_IP/rock-paper-scissors-game/

It works, but visitors would have to know your folder names.

Classroom line

The user doesn't know our folder's name, right?

Root at the parent folder: each projectopens at its folder name .../projects/projects/ (root) music-player/ dad-jokes-generator/ rock-paper-scissors-game/ ... dozens more http://PUBLIC_IP/music-player/ http://PUBLIC_IP/dad-jokes-generator/ http://PUBLIC_IP/rock-paper-...game/ Works, but visitors do not know your folder names. The proper way for many sites: a domain nameand a server block for each site (next chapter).

Figure 7. Root at the parent folder: each project at http://PUBLIC_IP/folder-name/. The proper way is a domain and a server block per site.

The proper way. Each site gets its own domain name and its own server block. You've also seen the other option: separate ports. Domains and server blocks come in the next chapter.

Classroom line

If you want to host more than one website, you actually need a domain name.

Classroom line

Hosting fifty-five websites means writing fifty-five server blocks.

8. Small things that trip people up

Each of these small mistakes produces a confusing error. Knowing them ahead saves you an hour of debugging.

  1. URLs with spaces or brackets. Put the whole URL in double quotes, or the shell splits it:

    sudo wget "https://example.com/files/my song (live).mp3"
    
  2. main.zip.1. If main.zip already exists, wget saves the next download as main.zip.1. Delete the old file first (sudo rm main.zip), or name the download yourself:

    sudo wget -O site2.zip https://github.com/OWNER/REPO/archive/refs/heads/main.zip
    
  3. sudo for unzip. /usr/share/nginx and its html folder belong to root, so unzip and mv there need sudo.

  4. Quality varies. Anyone can publish a repo. Some look polished, some look rough. Preview before you promise anything.
  5. Check the LICENSE. Before you reuse a template, or sell a site built from one, open the repo's LICENSE file and follow it; give credit where it asks.

A real skill. Suppose a local bakery or tuition class wants a simple website. You can pick a template whose licence allows it, change the text and images, and host it on EC2.

Classroom line

You can earn money from the people around you.

9. Warning: phishing login pages

Phishing: look-alike login pages

The same hosting skill is misused by attackers. Know how it works so you don't fall for it.

  1. An attacker copies the look of a real login page, suppose we mean Instagram's, and hosts it on their own server.
  2. They send the link in a message: "Your account will be blocked, log in now."
  3. The page looks real, so the victim types the username and password.
  4. The form sends them to the attacker's server, not to the real company.

Protect yourself:

  1. Check the domain in the address bar before you type a password.
  2. Don't log in from links in messages. Open the app, or type the address yourself.
  3. Turn on two-factor sign-in or passkeys.
  4. Report fake pages to the real company.

Classroom line

They'll think it's Instagram, so they'll type their username and password.

Classroom line

This is exactly what's called a phishing attack.

Warning: how a phishing login pagesteals passwords 1. An attacker copies the look of a reallogin page and hosts it on their ownserver. 2. They send the link in a message: youraccount will be blocked, log in now. 3. The page looks real, so the victim typesthe username and password. 4. The form sends them to the attackerserver, not to the real company. Protect yourself Check the domain in the address bar beforetyping a password. Do not log in from links in messages; open theapp or type the address yourself. Turn on two-factor sign-in or passkeys, andreport fake pages.

Figure 8. How a phishing page steals passwords, and four ways to protect yourself.

10. Clean up and what's next

A practice server you forget keeps costing money. Terminating it when you are done is part of the job.

Step 1. When practice is over, terminate the instance in the EC2 console so it stops costing money.

Next. Hosting several websites on one server with domain names and server blocks.

11. The whole flow on one page

  1. Find a public repo whose language bar shows only HTML, CSS and JavaScript.
  2. ssh -i mykey.pem ec2-user@PUBLIC_IP (key readable only by you: chmod 400, or Windows Properties).
  3. Right-click Download ZIP, copy the link.
  4. cd /usr/share/nginx, sudo wget <link>, sudo unzip master.zip, sudo mv REPO-master tensites.
  5. cd and ls until you see index.html; pwd.
  6. sudo nano /etc/nginx/nginx.conf: root <that path>;.
  7. sudo service nginx reload, open http://PUBLIC_IP/.
  8. Check the LICENSE; terminate the instance when done.

12. Hands-on lab: from a GitHub repository to a live site

In real work the code comes from GitHub, not from your keyboard. This lab takes a public HTML/CSS/JavaScript repository and puts it live with Nginx, with a check at every step.

  1. Pick a static repository
    • Do: On GitHub, open a public repository whose language bar shows only HTML, CSS and JavaScript, with index.html at the top level.
    • Check: You can see index.html in the file list.
    • Why: Nginx alone can only serve plain files. A repo with Java, Python or PHP needs a backend, which comes later in the course.
  2. Fix the key and log in
    • Command: chmod 400 mykey.pem && ssh -i mykey.pem ec2-user@PUBLIC_IP
    • You should see: The ec2-user prompt.
    • Check: No UNPROTECTED PRIVATE KEY FILE warning.
    • Why: ssh refuses a key others can read. On Windows, use the file's Properties → Security instead of chmod.
  3. Start Nginx
    • Command: sudo yum install nginx -y && sudo service nginx start
    • You should see: Complete! (or Nothing to do.), then the systemctl redirect line.
    • Check: http://PUBLIC_IP/ shows the Nginx welcome page.
    • Why: Seeing the welcome page first proves Nginx and port 80 work, so any later problem is in your files or settings.
  4. Download the ZIP on the server
    • Command: cd /usr/share/nginx && sudo wget https://github.com/OWNER/REPO/archive/refs/heads/master.zip
    • You should see: master.zip ... saved.
    • Check: ls shows master.zip.
    • Why: Copy the link from Code → Download ZIP exactly; some repos use main. wget on the server is faster than downloading to your laptop and uploading with scp.
  5. Unzip and rename
    • Command: sudo unzip master.zip && sudo mv REPO-master mysite
    • You should see: One inflating: line per file.
    • Check: ls mysite shows index.html.
    • Why: A short folder name keeps the root line simple. index.html must sit directly inside, or Nginx shows 403 or 404.
  6. Point Nginx at the folder
    • Command: sudo nano /etc/nginx/nginx.conf
    • You should see: In the server block set root /usr/share/nginx/mysite;. Save and exit.
    • Check: sudo nginx -t → syntax is ok and test is successful.
    • Why: root tells Nginx which folder is the website. Test before reload so a typo never takes the site down.
  7. Reload and open the site
    • Command: sudo service nginx reload
    • You should see: Redirecting to /bin/systemctl reload nginx.service
    • Check: http://PUBLIC_IP/ shows the repository's site, with its styles and images.
    • Why: If the page shows but without styles, a CSS path is wrong or a file name differs in case; open DevTools → Network and look for 404s.
  8. Terminate when practice is over
    • Do: EC2 console → select the instance → Instance state → Terminate instance.
    • Check: State Terminated; it disappears from the list after a while.
    • Why: The code still lives on GitHub, so nothing is lost. A forgotten server keeps costing money.
  9. Install git and clone instead of ZIP
    • Command: sudo yum install git -y && cd /usr/share/nginx && sudo git clone https://github.com/OWNER/REPO.git mysite2
    • You should see: Cloning into 'mysite2'... then Receiving objects: 100% and Resolving deltas: 100%.
    • Check: ls mysite2 lists the repo files, plus a hidden .git (see with ls -a).
    • Why: clone keeps history, so later you only git pull to update.
  10. Find where index.html really is
    • Command: cd /usr/share/nginx/mysite2 && find . -name index.html
    • You should see: Paths like ./index.html or ./project-3/index.html.
    • Check: Pick the folder you want to publish.
    • Why: Nginx root must point at the folder that holds index.html, not the repo top.
  11. Copy the exact path with pwd
    • Command: cd project-3 && pwd
    • You should see: /usr/share/nginx/mysite2/project-3
    • Check: Paste this into root …; in nginx.conf.
    • Why: Typing long paths by hand is the top cause of 404s.
  12. Point root, test, reload
    • Command:
      sudo nano /etc/nginx/nginx.conf   # root /usr/share/nginx/mysite2/project-3;
      sudo nginx -t && sudo service nginx reload
    • You should see: syntax is ok, test is successful, Redirecting to /bin/systemctl reload nginx.service.
    • Check: http://PUBLIC_IP/ shows project 3.
    • Why: One root per server block; switch projects by changing one line.
  13. Update after a new commit
    • Command: cd /usr/share/nginx/mysite2 && sudo git pull
    • You should see: Already up to date. or a list of changed files.
    • Check: Refresh the browser; changes appear (no reload needed for HTML).
    • Why: Static files are read fresh on each request.

13. Try at home

Try at home

Task 1: one site

  1. Fix your key's permissions if ssh complains.
  2. Find a static repo, sudo wget its ZIP into /usr/share/nginx, unzip it and rename it.
  3. Set root, reload and open http://PUBLIC_IP/.

Task 2: many projects

  1. Download a repo with many mini-projects into /usr/share/nginx/html.
  2. Find one project's index.html, run pwd, set root, reload.
  3. Switch to a second project the same way.
  4. Set root to the parent folder and open two projects by folder name.

When you're done, terminate the instance.

Common errors and fixes

Error / symptomFix
UNPROTECTED PRIVATE KEY FILE!chmod 400 mykey.pem on Mac/Linux (Windows: fix file permissions).
404 Not Found from wgetBranch is main, not master (or the reverse); copy the ZIP link from the repo's Code button.
403 Forbiddenroot points at a folder with no index.html; run find . -name index.html.
git: command not foundsudo yum install git -y.
Site needs npm/buildStatic only here; React/Node repos need a build step first.

FAQ

Q. wget ZIP or git clone?

ZIP is quick for a one-off. clone is better if you will update.

Q. Private repo?

Needs a token or deploy key; don't put your password on the server.

Q. Is any GitHub login page safe?

Only github.com. Check the address bar; phishing copies look the same.

Q. Why /usr/share/nginx?

It's Nginx's default html area on Amazon Linux; any folder works if root points there.

Recap

In short

  1. GitHub stores code; one project is one repository. Public repos can be downloaded by anyone, private ones only by people you allow.
  2. Only HTML, CSS and JavaScript in the language bar = static, Nginx can serve it.
  3. UNPROTECTED PRIVATE KEY FILE: chmod 400 on Linux and Mac; on Windows give only your user Read.
  4. Get code onto the server with Download ZIP + scp, or the ZIP link + sudo wget.
  5. sudo unzip, sudo mv to a short name, then point root at the folder holding index.html.
  6. Lost in folders? cd and ls until you see index.html, then pwd and paste.
  7. Root at a parent folder opens projects by folder name; for many sites use domains and server blocks.
  8. pwd before rm -rf *, quote odd URLs, watch for file.zip.1, check the LICENSE, and never trust login links in messages.

Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. OWNER/REPO stand for any public repository; tensites, projects, the project folder names and mykey.pem are examples for learning; PUBLIC_IP stands for your instance's public IPv4 address. Outputs are shortened with "..."; the hostname in the prompt is illustrative.

Practise this chapter

Interview questions and answers

When would you choose Git clone instead of a ZIP download for a release workflow?

Use a checkout when you need to inspect history, update and compare revisions, and identify the commit to release. Use a ZIP when you need a one-time snapshot. In both cases publish the checked browser-ready output from a separate directory.

A successful git pull did not change what visitors see. Where do you look?

Check the current commit and whether a build was needed. Then compare the published output location with Nginx’s effective document root. Confirm the lab URL and a visible version marker. Updating the checkout does not necessarily update the released files.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Two students have folders named project from the same Git repository. What distinguishes the exact code each checked out?

Answer and explanation

D. The Git commit ID

A commit identifies a recorded version. git log -1 shows the current checkout’s latest commit so you can compare versions.

2. The repository needs a frontend build to produce dist/. Which files should the static document root normally contain?

Answer and explanation

D. The browser-ready output intended for the release

The browser needs the prepared files. Keep the working checkout and private settings separate from the published output.

3. You copy a Python backend repository directly into a static Nginx document root. Why is that insufficient to run the API?

Answer and explanation

A. The backend needs a running Python application process

Nginx can serve static files. Dynamic requests need an application process and the configured hand-off to it.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Goa Beach Stays is a hospitality business in Panaji. Rosario Fernandes looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 12

Easy Restart a service after a change

Config changes only apply after the service restarts or reloads.

Restart the nginx service.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Check if a service is running

When a site is down, first check whether the web server process is running.

Show the status of the httpd service.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install a package on Ubuntu

Ubuntu uses apt. Package names differ: on Ubuntu Apache is apache2.

Install the apache2 package on Ubuntu without being asked to confirm.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Install a package on Amazon Linux

dnf is the package manager on Amazon Linux 2023. -y answers yes for you.

Install the httpd package on Amazon Linux 2023 without being asked to confirm.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Download code from GitHub

git clone copies the whole repository to the server, ready to deploy.

Clone https://github.com/goabeachstays/website.git into the current folder.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Test a website from the server

curl shows whether the web server answers, even before DNS is ready.

Request http://localhost and show only the response headers.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Port for SSH

Security group rules need the right port.

Which TCP port must the security group open for SSH?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Test the nginx config

A test catches typos before a restart takes your site down.

Check the nginx configuration files for errors.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Start a service now and at boot

enable makes it start after reboot; --now also starts it right away.

Enable the nginx service and start it immediately, in one command.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Open port 80 to the world

Visitors can reach your website only if the security group allows HTTP.

Allow inbound TCP port 80 from 0.0.0.0/0 on security group sg-013a13c4b3634c3b2.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium CloudFormation: web security group

Opening only 443 keeps the server safer.

Template with an AWS::EC2::SecurityGroup that allows TCP 443 from 0.0.0.0/0. Add a GroupDescription.

  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard Enable an nginx site on Ubuntu

On Ubuntu, a site is enabled by a symbolic link from sites-available to sites-enabled.

Create a symbolic link to /etc/nginx/sites-available/goabeachstays inside /etc/nginx/sites-enabled/.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: GitHub repository basics. Most projects you host come from GitHub. You must read a repo before using it. A repository is a project folder on GitHub. The language bar shows if it is static (HTML, CSS) or needs a backend. Check the language bar and the LICENSE before hosting. HTML 60%, CSS 30%, JS 10% = static, Nginx alone can host it.
Revision card: GitHub repository basics · Download PNG
Revision card: Fix UNPROTECTED PRIVATE KEY FILE. SSH refuses a key that other users can read. The .pem file must be readable only by you. 400 = owner read only. Linux/Mac: chmod 400. Windows: remove other users in file Properties › Security. Fix:
Revision card: Fix UNPROTECTED PRIVATE KEY FILE · Download PNG
Revision card: Get a repo onto the server with wget. Downloading to your laptop and uploading again is slow. wget downloads a URL straight onto the server. unzip extracts it. Copy the Download ZIP link, wget it in quotes, unzip, then point Nginx root to the folder. Commands:
Revision card: Get a repo onto the server with wget · Download PNG
Revision card: Set the Nginx root folder. The site shows the Nginx test page until Nginx knows where your files are. root is the folder Nginx serves. It must contain index.html. cd into the folder with index.html, run pwd, paste that path as root, nginx -t, reload. In nginx.conf:
Revision card: Set the Nginx root folder · Download PNG
Comparison: Public repository vs Private repository. Public repository: A GitHub repo anyone can view and download. Private repository: A GitHub repo only invited people can see.
Comparison: Public repository vs Private repository · Download PNG
Comparison: Download ZIP + scp vs wget on the server. Download ZIP + scp: Download to your laptop, then upload to EC2. wget on the server: Download straight from GitHub onto EC2.
Comparison: Download ZIP + scp vs wget on the server · Download PNG
Interview card: How do you tell if a GitHub project can be hosted on Nginx alone?. Look at the language bar: only HTML, CSS and JavaScript means static. PHP, Python or Node needs a runtime and maybe a database. HTML 70% CSS 30% › Nginx root. PHP 80% › LEMP stack.
Interview card: How do you tell if a GitHub project can be hosted on Nginx alone? · Download PNG
Interview card: Why run pwd before rm -rf *?. rm -rf * deletes everything in the CURRENT folder with no undo. In the wrong folder it can wipe the website or the system. pwd shows /usr/share/nginx/html › then delete.
Interview card: Why run pwd before rm -rf *? · Download PNG
Interview card: How does a phishing login page steal passwords?. It copies a real login page on a look-alike domain and saves what you type. The page looks identical, so people trust it. Check the domain and use MFA: faceb00k-login.com is not facebook.com.
Interview card: How does a phishing login page steal passwords? · Download PNG

More cards: Ravi Sir's Cards.