{"id":25847347,"url":"https://github.com/kaalpanikh/static-site-server","last_synced_at":"2026-04-13T09:31:24.277Z","repository":{"id":275781889,"uuid":"927084695","full_name":"kaalpanikh/static-site-server","owner":"kaalpanikh","description":"Static site server on AWS: Deploy static websites with Nginx and Cloudflare DNS management.","archived":false,"fork":false,"pushed_at":"2025-02-28T17:39:40.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-27T12:55:22.250Z","etag":null,"topics":["aws","cloudflare","deployment","dns","nginx","static-site"],"latest_commit_sha":null,"homepage":"https://static.nikhilmishra.live","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaalpanikh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T11:31:18.000Z","updated_at":"2025-02-28T17:39:44.000Z","dependencies_parsed_at":"2025-02-04T15:33:13.748Z","dependency_job_id":"61df0a9c-2fa7-4ce0-b0f9-72b932494b57","html_url":"https://github.com/kaalpanikh/static-site-server","commit_stats":null,"previous_names":["kaalpanikh/static-site-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kaalpanikh/static-site-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaalpanikh%2Fstatic-site-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaalpanikh%2Fstatic-site-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaalpanikh%2Fstatic-site-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaalpanikh%2Fstatic-site-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaalpanikh","download_url":"https://codeload.github.com/kaalpanikh/static-site-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaalpanikh%2Fstatic-site-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31746291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-13T09:16:15.125Z","status":"ssl_error","status_checked_at":"2026-04-13T09:16:05.023Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cloudflare","deployment","dns","nginx","static-site"],"created_at":"2025-03-01T10:18:52.576Z","updated_at":"2026-04-13T09:31:24.257Z","avatar_url":"https://github.com/kaalpanikh.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Static Site Server Project\n\nThis project demonstrates how to set up a secure static website using:\n- Amazon EC2 (Amazon Linux 2023)\n- Nginx web server\n- Let's Encrypt SSL/TLS certificates\n- Custom domain configuration\n- Automated deployment script\n\nThe project currently includes:\n1. A static website (`index.html`) with modern styling\n2. Nginx configuration for the static site (`static-site.conf`)\n3. Automated deployment script (`deploy.sh`) for secure file transfer\n4. SSL/TLS certificate setup using Let's Encrypt\n\n## Project Page\n\nFor more details about this project, visit the project page on roadmap.sh:  \n[Static Site Server Project](https://roadmap.sh/projects/static-site-server) \u0026\n[EC2 Instance Project](https://roadmap.sh/projects/ec2-instance)  \n\n## Table of Contents\n\n- [Overview](#overview)\n- [Prerequisites](#prerequisites)\n- [Architecture](#architecture)\n- [Deployment Process](#deployment-process)\n- [Request Flow](#request-flow)\n- [Installation](#installation)\n- [Setup and Deployment](#setup-and-deployment)\n  - [AWS EC2 Setup](#aws-ec2-setup)\n  - [Nginx Installation and Configuration](#nginx-installation-and-configuration)\n  - [Deploying Your Static Site](#deploying-your-static-site)\n- [DNS Configuration with Cloudflare](#dns-configuration-with-cloudflare)\n- [Notes on HTTPS](#notes-on-https)\n- [Troubleshooting](#troubleshooting)\n- [License](#license)\n\n## Overview\n\nIn this project, you will:\n- Launch an AWS EC2 instance.\n- Install and configure Nginx to serve a static site.\n- Deploy your static site files using a deployment script (using `scp`).\n- Configure your DNS on Cloudflare so that your subdomain (e.g., `static.nikhilmishra.live`) points to your EC2 instance.\n- (Optional) Configure HTTPS on your EC2 server. (For now, we are using HTTP on the server with Cloudflare in Full mode.)\n\n## Prerequisites\n\n- **AWS Account:** You need an active AWS account and an EC2 instance (preferably running Amazon Linux or Ubuntu).\n- **SSH Access:** Ensure you have SSH access to your EC2 instance with your private key (e.g., `~/.ssh/my_second_key`).\n- **Domain and Cloudflare Account:** Your domain (e.g., `nikhilmishra.live`) is managed through Cloudflare, with an A record pointing to your EC2 instance's public IP.\n- **Basic Knowledge of Linux and Nginx:** Familiarity with terminal commands, file editing, and basic Nginx configuration.\n\n## Architecture\n\nBelow is the architecture diagram for the static site server setup:\n\n```mermaid\ngraph TD\n    A[Client Browser] --\u003e|HTTPS Request| B[Cloudflare DNS]\n    B --\u003e|HTTP Request| C[AWS EC2 Instance]\n    C --\u003e|Serves| D[Nginx Web Server]\n    D --\u003e|Hosts| E[Static Website Files]\n    F[Local Development Environment] --\u003e|Deploy via SCP| C\n    \n    subgraph \"AWS Cloud\"\n        C\n        D\n        E\n    end\n    \n    subgraph \"Cloudflare\"\n        B --\u003e|SSL Termination| B1[Edge Server]\n        B1 --\u003e|Cache| B2[CDN]\n    end\n    \n    classDef aws fill:#FF9900,stroke:#232F3E,color:white;\n    classDef cloudflare fill:#F6821F,stroke:#232F3E,color:white;\n    classDef nginx fill:#009639,stroke:#232F3E,color:white;\n    class C,E aws;\n    class B,B1,B2 cloudflare;\n    class D nginx;\n```\n\n## Deployment Process\n\nThe following diagram illustrates the deployment process using the `deploy.sh` script:\n\n```mermaid\nflowchart TD\n    A[Start Deployment] --\u003e B{SSH Key Exists?}\n    B --\u003e|No| C[Error: SSH Key Not Found]\n    B --\u003e|Yes| D[Test SSH Connection]\n    D --\u003e|Failed| E[Error: SSH Connection Failed]\n    D --\u003e|Success| F[Create Temporary Directory on Server]\n    F --\u003e|Success| G[Copy Files to Temporary Directory]\n    G --\u003e|Failed| H[Clean Up \u0026 Exit]\n    G --\u003e|Success| I[Move Files to Final Location]\n    I --\u003e|Failed| J[Clean Up \u0026 Exit]\n    I --\u003e|Success| K[Deployment Complete]\n    \n    style A fill:#4CAF50,stroke:#006400,color:white\n    style K fill:#4CAF50,stroke:#006400,color:white\n    style C fill:#FF5252,stroke:#B71C1C,color:white\n    style E fill:#FF5252,stroke:#B71C1C,color:white\n    style H fill:#FF5252,stroke:#B71C1C,color:white\n    style J fill:#FF5252,stroke:#B71C1C,color:white\n```\n\n## Request Flow\n\nThis sequence diagram shows how a client request flows through the system:\n\n```mermaid\nsequenceDiagram\n    participant User as User\n    participant Browser as Browser\n    participant Cloudflare as Cloudflare\n    participant EC2 as EC2 Instance\n    participant Nginx as Nginx Server\n    \n    User-\u003e\u003eBrowser: Enter static.nikhilmishra.live\n    Browser-\u003e\u003eCloudflare: DNS Resolution\n    Cloudflare--\u003e\u003eBrowser: IP Address (44.204.60.96)\n    Browser-\u003e\u003eCloudflare: HTTPS Request\n    Note over Cloudflare: SSL Termination\n    Cloudflare-\u003e\u003eEC2: HTTP Request\n    EC2-\u003e\u003eNginx: Forward Request\n    Nginx-\u003e\u003eNginx: Process Request\n    Note over Nginx: Find Static Files\n    Nginx--\u003e\u003eEC2: Serve HTML/CSS/JS\n    EC2--\u003e\u003eCloudflare: HTTP Response\n    Cloudflare--\u003e\u003eBrowser: HTTPS Response\n    Browser--\u003e\u003eUser: Display Content\n    \n    Note over Cloudflare,EC2: Cloudflare is set to 'Flexible' SSL mode,\u003cbr/\u003eterminating SSL at Cloudflare's edge\n```\n\n## Installation\n\n1.  **Update Your System:**\n\n    ```bash\n    sudo dnf update -y\n    ```\n\n2.  **Install Nginx:**\n\n    ```bash\n    sudo dnf install -y nginx\n    sudo systemctl enable --now nginx\n    ```\n\n3.  **Install Certbot and the Nginx Plugin:**\n\n    ```bash\n    sudo dnf install -y certbot python3-certbot-nginx\n    ```\n\n4.  **Deploy the Static Site:**\n    - Update the deployment script variables in `deploy.sh`:\n      - `REMOTE_USER`: Your EC2 instance username\n      - `REMOTE_HOST`: Your EC2 instance public IP or domain\n      - `SSH_KEY`: Path to your SSH key\n    - Make the script executable and run it:\n      ```bash\n      chmod +x deploy.sh\n      ./deploy.sh\n      ```\n\n## Setup and Deployment\n\n### AWS EC2 Setup\n\n1. **Launch an EC2 Instance:**  \n   Create and configure an EC2 instance (using Amazon Linux, Ubuntu, or similar). Ensure that your security group allows inbound traffic on port 22 (SSH) and port 80 (HTTP).\n\n2. **SSH Access:**  \n   Connect to your instance using:\n   ```bash\n   ssh -i ~/.ssh/my_second_key ec2-user@\u003cyour-ec2-public-ip\u003e\n   ```\n\n### Nginx Installation and Configuration\n\n1. **Configure Nginx:**\n    - Our Nginx configuration (`static-site.conf`) is already set up with:\n      - Domain configuration\n      - Root directory settings\n      - Basic security headers\n      - Access and error logging\n    - Copy the configuration to Nginx:\n      ```bash\n      sudo cp static-site.conf /etc/nginx/conf.d/\n      sudo nginx -t\n      sudo systemctl reload nginx\n      ```\n\n2. **Configure DNS:**\n    - Point your domain to your EC2 instance's public IP\n    - Update `server_name` in `static-site.conf` with your domain\n\n3. **SSL Certificate Setup:**\n    ```bash\n    sudo certbot --nginx -d your_domain.com\n    ```\n    Follow the prompts to complete the certificate installation.\n\n### Deploying Your Static Site\n\nUse the following `deploy.sh` script (which uses `scp`) to deploy your site from your local machine:\n\n```bash\n#!/bin/bash\n\n########\n# Author: Your Name\n# Date: 2025-02-04\n#\n# Version: v1.2\n#\n# Static Site Server Deployment Script\n#\n# This script uses scp to sync your static site from your local machine to a remote server.\n########\n\n# Enable debug mode\nset -x\n\n# Change to script directory\ncd \"$(dirname \"$0\")\" || exit\n\n# Remote server details\nREMOTE_USER=\"ec2-user\"\nREMOTE_HOST=\"44.204.60.96\"\nREMOTE_DIR=\"/usr/share/nginx/html\"\n\n# SSH key path\nSSH_KEY=\"$HOME/.ssh/my_second_key\"\n\n# Check if SSH key exists\nif [ ! -f \"$SSH_KEY\" ]; then\n    echo \"Error: SSH key not found at $SSH_KEY\"\n    exit 1\nfi\n\n# Test SSH connection first\necho \"Testing SSH connection...\"\nif ! ssh -i \"$SSH_KEY\" -o BatchMode=yes -o ConnectTimeout=5 \"$REMOTE_USER@$REMOTE_HOST\" echo \"SSH connection successful\"; then\n    echo \"Error: SSH connection failed. Please check your SSH key and server configuration.\"\n    exit 1\nfi\n\n# Create a temporary directory on the remote server\necho \"Creating temporary directory on remote server...\"\nTEMP_DIR=\"/tmp/static-site-$(date +%s)\"\nif ! ssh -i \"$SSH_KEY\" \"$REMOTE_USER@$REMOTE_HOST\" \"mkdir -p $TEMP_DIR\"; then\n    echo \"Error: Failed to create temporary directory\"\n    exit 1\nfi\n\n# Copy files to temporary directory\necho \"Copying files to remote server...\"\nif ! scp -i \"$SSH_KEY\" -r ./* \"$REMOTE_USER@$REMOTE_HOST:$TEMP_DIR/\"; then\n    echo \"Error: Failed to copy files\"\n    ssh -i \"$SSH_KEY\" \"$REMOTE_USER@$REMOTE_HOST\" \"rm -rf $TEMP_DIR\"\n    exit 1\nfi\n\n# Move files to final location\necho \"Moving files to final location...\"\nif ! ssh -i \"$SSH_KEY\" \"$REMOTE_USER@$REMOTE_HOST\" \"sudo rm -rf $REMOTE_DIR/* \u0026\u0026 sudo cp -r $TEMP_DIR/* $REMOTE_DIR/ \u0026\u0026 sudo chown -R nginx:nginx $REMOTE_DIR \u0026\u0026 sudo chmod -R 755 $REMOTE_DIR \u0026\u0026 rm -rf $TEMP_DIR\"; then\n    echo \"Error: Failed to move files to final location\"\n    ssh -i \"$SSH_KEY\" \"$REMOTE_USER@$REMOTE_HOST\" \"rm -rf $TEMP_DIR\"\n    exit 1\nfi\n\necho \"Deployment completed successfully!\"\n```\n\n1. Save the file as `deploy.sh` in your project folder.\n2. Make it executable:\n   ```bash\n   chmod +x deploy.sh\n   ```\n3. Run it from Git Bash or WSL:\n   ```bash\n   ./deploy.sh\n   ```\n\n## DNS Configuration with Cloudflare\n\n1. **Log in to Cloudflare:**  \n   Go to your Cloudflare dashboard and select your domain (e.g., `nikhilmishra.live`).\n\n2. **Create an A Record:**  \n   Create an A record for your subdomain:\n   - **Name:** static  \n   - **IPv4 Address:** 44.204.60.96  \n   - **Proxy status:** Enable Cloudflare proxy (orange cloud) if you wish to use Cloudflare’s SSL and caching features.\n\n3. **SSL Settings:**  \n   If you are not handling HTTPS on your EC2 server, you can set Cloudflare’s SSL mode to **Flexible**. This will encrypt traffic between the visitor and Cloudflare while connecting to your server via HTTP. Alternatively, if you later configure HTTPS on your server, you can switch to **Full** or **Full (strict)**.\n\n## Notes on HTTPS\n\n- **Current Setup:**  \n  At this time, the EC2 server is serving only HTTP. Cloudflare is set to handle SSL on the edge.\n  \n- **Future Improvements:**  \n  You may choose to set up HTTPS on your EC2 server using a self-signed certificate or a free Let's Encrypt certificate for end-to-end encryption. For now, Cloudflare's Flexible SSL mode will secure the connection between the client and Cloudflare.\n\n## Troubleshooting\n\n- **Nginx Issues:**  \n  If your site does not display correctly, check the Nginx error logs:\n  ```bash\n  sudo tail -f /var/log/nginx/error.log\n  ```\n- **DNS Propagation:**  \n  DNS changes can take a few minutes to propagate. Use tools like [DNS Checker](https://dnschecker.org) to confirm that your subdomain resolves to your server’s IP.\n- **Deployment Problems:**  \n  Ensure that your SSH key and remote credentials are correct. You can manually test SSH connectivity:\n  ```bash\n  ssh -i ~/.ssh/my_second_key ec2-user@44.204.60.96\n  ```\n\n## License\n\nThis project is provided for educational purposes. Modify and distribute as needed.\n\n---\n\nWith these instructions and the provided script, you should be able to deploy your static site server and serve your content at [static.nikhilmishra.live](https://static.nikhilmishra.live) via Cloudflare. Happy coding and learning!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaalpanikh%2Fstatic-site-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaalpanikh%2Fstatic-site-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaalpanikh%2Fstatic-site-server/lists"}