Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 95 additions & 107 deletions SOLUTION.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Enable HTTP Access and Configure Web Server Lab - Solution

**Student Name:** [Your Name]
**Date Completed:** [Date]
**Student Name:** Julio Cesar Aldana Almanza
**Date Completed:** 07/15/2026

---

# Environment Details

| Item | Value |
|------|-------|
| Instance ID | [i-xxxxxxxxxxxxx] |
| Public IP | [x.x.x.x] |
| Instance ID | i-03ddc9a164600a60b |
| Public IP | 54.157.199.117 |
| Test URL | [http://x.x.x.x] |
| Security Group ID | [sg-xxxxxxxx] |
| Region | [eu-west-1] |
| My IP (SSH source) | [x.x.x.x/32] |
| AMI | [Amazon Linux 2023] |
| Security Group ID | sg-0a39bd2f950095e45 |
| Region | us-east-1 |
| My IP (SSH source) | 92.209.213.67/32 |
| AMI | Amazon Linux 2023 |

---

Expand All @@ -26,23 +26,23 @@
Save your screenshot as:

```
screenshots/01-security-group-http-rule.png
Screenshots/01-security-group-http-rule.png
```

![Security Group HTTP Rule](screenshots/01-security-group-http-rule.png)
![Security Group HTTP Rule](Screenshots/01-security-group-http-rule.png)

---

- [ ] HTTP (80) inbound from `0.0.0.0/0` added
- [ ] SSH (22) inbound from **my IP only**
- [ ] **No** rule for port 8080
- [x] HTTP (80) inbound from `0.0.0.0/0` added
- [x] SSH (22) inbound from **my IP only**
- [x] **No** rule for port 8080

### Inbound rules on my security group

| Type | Port | Source | Description |
|------|------|--------|-------------|
| [SSH] | [22] | [YOUR_IP/32] | [Admin access] |
| [HTTP] | [80] | [0.0.0.0/0] | [Public HTTP access] |
| SSH | 22 | 92.209.213.67/32 | Admin access |
| HTTP | 80 | 0.0.0.0/0 | Public HTTP access |

---

Expand All @@ -51,44 +51,41 @@ screenshots/01-security-group-http-rule.png
**Your Answer**

```
_______________________________________________________________

_______________________________________________________________

_______________________________________________________________
Because Nginx will use 8080 port so it needs to stay private.
```

---

# Step 2: Install Nginx and Node.js

- [ ] `sudo dnf install -y nginx nodejs` completed
- [ ] `nginx -v` prints a version
- [ ] `node -v` prints a version
- [ ] `npm -v` prints a version
- [x] `sudo dnf install -y nginx nodejs` completed
- [x] `nginx -v` prints a version
- [x] `node -v` prints a version
- [x] `npm -v` prints a version

### Versions I got

```text
[nginx -v output]
[node -v output]
[npm -v output]
nginx version: nginx/1.30.3
v18.20.8
10.8.2
```

---

# Step 3: Create the Node.js Application

- [ ] `~/app` created, `npm init -y` run
- [ ] `express` installed
- [ ] `index.js` created, listening on **8080**
- [ ] `node index.js &` running
- [ ] `curl localhost:8080` returns the HTML **before** touching Nginx
- [x] `~/app` created, `npm init -y` run
- [x] `express` installed
- [x] `index.js` created, listening on **8080**
- [x] `node index.js &` running
- [x] `curl localhost:8080` returns the HTML **before** touching Nginx

### `curl localhost:8080` output

```text
[Paste the HTML you got back]
<h1>Hello from ip-172-31-20-213.ec2.internal!</h1>
<p>You have successfully configured HTTP access</p>
```

---
Expand All @@ -98,9 +95,8 @@ _______________________________________________________________
**Your Answer**

```
_______________________________________________________________

_______________________________________________________________
The environment variable HOSTNAME is not set when the systemd starts the app,
that is why we have to use os.hostname, which is an api that always work.
```

---
Expand All @@ -112,23 +108,33 @@ _______________________________________________________________
Save your screenshot as:

```
screenshots/03-services-running.png
Screenshots/03-services-running.png
```

![Services Running](screenshots/03-services-running.png)
![Services Running](Screenshots/03-services-running.png)

---

- [ ] `/etc/nginx/conf.d/app.conf` created with `listen 80 default_server;`
- [ ] `proxy_pass http://127.0.0.1:8080;` set
- [ ] Stock `default_server` line removed from `/etc/nginx/nginx.conf`
- [ ] `sudo nginx -t` passes
- [ ] `systemctl start nginx` **and** `systemctl enable nginx` run
- [x] `/etc/nginx/conf.d/app.conf` created with `listen 80 default_server;`
- [x] `proxy_pass http://127.0.0.1:8080;` set
- [x] Stock `default_server` line removed from `/etc/nginx/nginx.conf`
- [x] `sudo nginx -t` passes
- [x] `systemctl start nginx` **and** `systemctl enable nginx` run

### My `app.conf`

```nginx
[Paste your app.conf here]
server {
listen 80 default_server;
server_name _;

location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```

---
Expand All @@ -138,11 +144,8 @@ screenshots/03-services-running.png
**Your Answer**

```
_______________________________________________________________

_______________________________________________________________

_______________________________________________________________
Because Nginx will refuse to start with a duplicate default server, proxy configuration will never be used
as Nginx returns back to the default server.
```

---
Expand All @@ -154,34 +157,34 @@ _______________________________________________________________
Save your screenshot as:

```
screenshots/02-browser-working-webpage.png
Screenshots/02-browser-working-webpage.png
```

![Browser Working Webpage](screenshots/02-browser-working-webpage.png)
![Browser Working Webpage](Screenshots/02-browser-working-webpage.png)

---

Work outward — the first test that fails tells you which layer is broken.

| # | Test | Run from | Expected | Got it |
|---|------|----------|----------|--------|
| 1 | `curl localhost:8080` | Instance | ✅ App HTML (the app is alive) | [ ] |
| 2 | `curl localhost` | Instance | ✅ Same HTML (Nginx proxies) | [ ] |
| 3 | `curl http://YOUR_PUBLIC_IP` | Laptop | ✅ Same HTML (security group allows 80) | [ ] |
| 4 | `http://YOUR_PUBLIC_IP` in a browser | Laptop | ✅ "Hello from ip-xxx..." page | [ ] |
| 1 | `curl localhost:8080` | Instance | ✅ App HTML (the app is alive) | ✅ App HTML (the app is alive) |
| 2 | `curl localhost` | Instance | ✅ Same HTML (Nginx proxies) | ✅ Same HTML (Nginx proxies) |
| 3 | `curl http://http://54.157.199.117/` | Laptop | ✅ Same HTML (security group allows 80) | ✅ Same HTML |
| 4 | `http://http://54.157.199.117/` in a browser | Laptop | ✅ "Hello from ip-xxx..." page | ✅ "Hello from 172-31-20-213.ec2.internal!|

---

### If test 1 passed but test 2 failed, which component is at fault?

```
_______________________________________________________________
Nginx
```

### If test 2 passed but test 3 failed, which component is at fault?

```
_______________________________________________________________
Security group
```

---
Expand All @@ -193,26 +196,26 @@ _______________________________________________________________
Save your screenshot as:

```
screenshots/04-curl-test.png
Screenshots/04-curl-test.png
```

![curl Test](screenshots/04-curl-test.png)
![curl Test](Screenshots/04-curl-test.png)

---

Prove the app port is private. **From your laptop:**

```bash
curl http://YOUR_PUBLIC_IP:8080
curl http://54.157.199.117:8080
```

- [ ] It **times out**. The app *is* listening on 8080, but the security group never lets my packet reach it.
- [x] It **times out**. The app *is* listening on 8080, but the security group never lets my packet reach it.

### How did it fail?

(Timeout is the correct answer. "Connection refused" would mean the packet **reached** the host — your security group is letting 8080 through.)

- [ ] Timed out / hung ✅ Correct
- [x] Timed out / hung ✅ Correct
- [ ] Connection refused ⚠️ Rules too permissive

---
Expand All @@ -223,16 +226,16 @@ Which of these did you hit during the lab? Tick each one you saw and note what f

| What you see | What it means | Saw it | What fixed it |
|---|---|---|---|
| **502 Bad Gateway** | Nginx is up but cannot reach the app on 8080 | [ ] | [ ] |
| **Welcome to nginx!** | Nginx is serving the stock default page, not proxying | [ ] | [ ] |
| **Connection refused** | Packet reached the host; nothing is listening | [ ] | [ ] |
| **Timeout / hangs** | Packet never reached the host — security group blocked it | [ ] | [ ] |
| **502 Bad Gateway** | Nginx is up but cannot reach the app on 8080 | No | [ ] |
| **Welcome to nginx!** | Nginx is serving the stock default page, not proxying | No | [ ] |
| **Connection refused** | Packet reached the host; nothing is listening | No | [ ] |
| **Timeout / hangs** | Packet never reached the host — security group blocked it | Yes | Allow it in sg |

---

### Did every test pass on the first attempt?

- [ ] Yes
- [x] Yes
- [ ] No

If no, what did you have to fix?
Expand Down Expand Up @@ -280,82 +283,67 @@ _______________________________________________________________
## 1. Why put Nginx in front of the app at all? Why not have Node listen on port 80 directly?

```
_______________________________________________________________

_______________________________________________________________

_______________________________________________________________
Having Nginxin front of the app gives you more advantages, such as a highly optimized HTTP parsing, faster file serving, reverse proxy and load balancing
```

---

## 2. You never opened port 8080, yet the app is reachable. Trace the path a packet takes from your browser to the Node process.

```
_______________________________________________________________

_______________________________________________________________

_______________________________________________________________
client → port 80 → nginx → port 8080 → Node → app
```

---

## 3. What is the difference between a 502 and a timeout, and why does knowing that save you time?

```
_______________________________________________________________

_______________________________________________________________

_______________________________________________________________
We can identify the root cause of the problem: if 502, the node app is dead. If timeout, then security group is blocking the transfer of data.
```

---

## 4. What would break if you removed `default_server` from your config? Why does a request to a raw IP behave differently from a request to a domain name?

```
_______________________________________________________________

_______________________________________________________________

_______________________________________________________________
Nothing will strictly break, but it can cause a surprising behavior. Nginx will choose a default server if no one is specified, so it will rely on
configuration order, losing control on how to handle unmatched requests.
```

---

# Cleanup

- [ ] Instance **stopped** (not terminated — later labs reuse it)
- [ ] HTTP rule kept (Lab M2.07 builds on this setup)
- [x] Instance **stopped** (not terminated — later labs reuse it)
- [x] HTTP rule kept (Lab M2.07 builds on this setup)

---

# What to Submit

Repository name: `ce-lab-enable-http-access` (**public**)

- [ ] `configs/app.conf` — my proxy configuration
- [ ] `configs/nginx.conf` — showing the `default_server` line removed
- [ ] `application/index.js`
- [ ] `application/package.json`
- [ ] `screenshots/01-security-group-http-rule.png`
- [ ] `screenshots/02-browser-working-webpage.png`
- [ ] `screenshots/03-services-running.png`
- [ ] `screenshots/04-curl-test.png`
- [ ] `README.md` with the steps I followed, my public IP and test URL, my security group ID and rules, troubleshooting, and the reflections
- [x] `configs/app.conf` — my proxy configuration
- [x] `configs/nginx.conf` — showing the `default_server` line removed
- [x] `application/index.js`
- [x] `application/package.json`
- [x] `Screenshots/01-security-group-http-rule.png`
- [x] `Screenshots/02-browser-working-webpage.png`
- [x] `Screenshots/03-services-running.png`
- [x] `Screenshots/04-curl-test.png`
- [x] `README.md` with the steps I followed, my public IP and test URL, my security group ID and rules, troubleshooting, and the reflections

---

# Submission Checklist

- [ ] GitHub repository created and **public**
- [ ] HTTP (80) allowed in security group; 8080 NOT allowed
- [ ] `curl http://YOUR_PUBLIC_IP` returns the app page from my laptop
- [ ] `curl http://YOUR_PUBLIC_IP:8080` times out (proof 8080 is private)
- [ ] `nginx -t` passes
- [ ] Nginx enabled to start on boot
- [ ] All 4 screenshots included
- [ ] README complete with reflections
- [ ] Repository URL submitted
- [x] GitHub repository created and **public**
- [x] HTTP (80) allowed in security group; 8080 NOT allowed
- [x] `curl http://YOUR_PUBLIC_IP` returns the app page from my laptop
- [x] `curl http://YOUR_PUBLIC_IP:8080` times out (proof 8080 is private)
- [x] `nginx -t` passes
- [x] Nginx enabled to start on boot
- [x] All 4 screenshots included
- [x] README complete with reflections
- [x] Repository URL submitted
Binary file added Screenshots/01-security-group-http-rule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/02-browser-working-webpage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/03-services-running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/04-curl-test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading