8. Hosting a Static Website and Changing the Configuration
8.1 Create the Sample Website and Upload Files
Server var he commands chalva – ~/mysite madhe index.html, CSS aani custom 404 page banel.
mkdir -p ~/mysite/css
cat > ~/mysite/index.html <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Cloud Website</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header><h1>Namaste from AWS EC2!</h1></header>
<main>
<p>This static website is served by a web server running on an EC2 instance.</p>
<ul>
<li>Cloud: Amazon Web Services</li>
<li>Server: EC2 in the Mumbai region</li>
<li>Content: HTML + CSS</li>
</ul>
</main>
<footer>Hosted in Ravindra sir's Cyber Security lab</footer>
</body>
</html>
EOF
cat > ~/mysite/css/style.css <<'EOF'
body { font-family: Arial, sans-serif; margin: 0; background: #f4f7fb; color: #222; }
header { background: #0b3d6e; color: #fff; padding: 20px; text-align: center; }
main { max-width: 700px; margin: 30px auto; background: #fff; padding: 20px; border-radius: 8px; }
footer { text-align: center; color: #777; padding: 20px; }
EOF
cat > ~/mysite/404.html <<'EOF'
<!DOCTYPE html><html><body><h1>404 - Page not found</h1><a href="/">Go home</a></body></html>
EOF
ls -R ~/mysite
Step 2 (common): ways to upload your own files
Option A — scp from your laptop (run on your laptop, not on the server):
# Linux / macOS / Windows PowerShell - upload whole folder to the server's home directory
scp -i mykey.pem -r ./mysite ec2-user@<PUBLIC_IP>:~/
# Ubuntu server:
scp -i mykey.pem -r ./mysite ubuntu@<PUBLIC_IP>:~/
Option B — git clone (run on the server). Push your site to a GitHub repository first:
sudo yum install -y git # AL2023 / CentOS (Ubuntu: sudo apt install -y git)
git clone https://github.com/<your-username>/<your-repo>.git ~/mysite
# later, to update:
cd ~/mysite && git pull
Option C — WinSCP / MobaXterm / FileZilla (SFTP): connect with host <PUBLIC_IP>, port 22, your user and private key, then drag and drop.
Deploying directly into the web root
You cannot scp directly into /var/www/... because it is owned by root. Either upload to your home folder and sudo cp (as shown below), or make your login user the owner of the site folder once: sudo chown -R $USER:$USER /var/www/mysite. Files stay world-readable (644), so the web server can still read them.
Step 3 (common): copy files and set permissions
sudo mkdir -p /var/www/mysite
sudo cp -r ~/mysite/* /var/www/mysite/
sudo find /var/www/mysite -type d -exec chmod 755 {} \;
sudo find /var/www/mysite -type f -exec chmod 644 {} \;
ls -la /var/www/mysite
Why this matters for security
755 for folders and 644 for files lets the web server read but not write. If the web server user could write into the web root, any file-upload or code-execution bug would let an attacker replace your pages (defacement) or plant a web shell.
Ravindra Bagale's Tip
scp ne direct /var/www madhe upload karayla gelyavar "Permission denied" yeto aani khup students laghech chmod 777 kartat. Nako! Aadhi home folder madhe upload kara, mag sudo cp kara – kiwa site folder cha owner ekdach tumcha user kara.
Practice task
Create the sample site on the server, then create your own two-page site on your laptop and upload it with scp -r to your home folder.