This repository provides a comprehensive guide and code to deploy a static website using Nginx. Follow the step-by-step instructions below to set up your own static website effortlessly.
- Static Website Deployment with Nginx
- Steps
- 1. Buy a Domain Name
- 2. Spin up an Ubuntu Server
- 3. SSH into the Server and Install Nginx
- 4. Download Website Files
- 5. Copy Website Files to Nginx Directory Using SCP
- 6. Validate the Website Using Server IP
- 7. Create A Record in DNS
- 8. Verify DNS Records Using
dig
- 9. Verify Website Setup Using DNS
- 10. Create Let's Encrypt Certificate and Configure Nginx
- 11. Validate SSL Using OpenSSL
- Note
- License
- Steps
- Go to a domain registrar website (e.g., Namecheap).
- Purchase a domain name of your choice.
- Choose a preferred cloud provider (e.g., AWS, DigitalOcean).
- Create an Ubuntu server instance.
ssh username@your_server_ip
sudo apt update
sudo apt install nginx
Find and download HTML files for your static website.
scp -r /path/to/your/local/website/* username@your_server_ip:/var/www/html/
- Open a web browser and enter your server's IP address.
- Log in to your domain registrar account.
- Find the DNS settings.
- Create an A record pointing to your server's IP address.
dig your_domain.com
- Open a web browser and enter your domain name.
sudo apt install certbot
sudo certbot --nginx -d your_domain.com
openssl s_client -connect your_domain.com:443
Make sure to replace your_domain.com
, your_server_ip
, and other placeholder values with your actual information.
-
Log In to Your Domain Registrar Account:
- Go to the website of your domain registrar (e.g., Namecheap, GoDaddy, etc.).
- Log in to your account using your credentials.
-
Navigate to DNS Management or Domain Management:
- Find the section in your account dashboard related to DNS management or domain settings.
-
Locate Your Domain:
- Locate the domain for which you want to create an A record.
-
Access DNS Settings:
- Look for options like "DNS Settings," "Manage Domains," or "DNS Management." The terminology may vary.
-
Add a New A Record:
- Within the DNS settings, find an option to add a new record.
- Select "A" (Address) as the record type.
-
Enter Details:
-
You'll typically be prompted to enter the following details:
- Name/Host/Alias: Leave it blank or enter
@
to indicate the root domain. - Value/Points To/Destination: Enter the IP address of your server.
- Name/Host/Alias: Leave it blank or enter
-
-
Save Changes:
- Save or apply the changes. This might involve clicking a "Save," "Add Record," or "Submit" button.
-
Propagation Time:
- DNS changes may take some time to propagate across the internet. It could take a few minutes to several hours for the changes to take effect.
Here's an example using Namecheap:
- Log in to your Namecheap account.
- Navigate to the "Domain List" or "Manage Domains."
- Find your domain and click on "Manage."
- Look for the "Advanced DNS" or "DNS" tab.
- Add a new A record with the server's IP address.
- Save the changes.
-
Sign in to AWS Console:
- Go to the AWS Management Console.
- Sign in to your AWS account.
-
Navigate to EC2:
- In the AWS Management Console, navigate to the EC2 service.
-
Launch an Instance:
- Click on the "Instances" link in the EC2 Dashboard.
- Click the "Launch Instance" button.
-
Choose an Amazon Machine Image (AMI):
- In the "Choose an Amazon Machine Image (AMI)" step, select an Ubuntu Server AMI. You can use the search bar to find the latest version of Ubuntu.
-
Choose an Instance Type:
- In the "Choose an Instance Type" step, select the instance type that suits your needs. The default selection is usually a good starting point (e.g., t2.micro).
-
Configure Instance:
- Click "Next: Configure Instance Details."
- In this step, you can configure various settings such as the number of instances, network settings, and more. The default settings are often sufficient for a basic setup.
-
Add Storage:
- Click "Next: Add Storage."
- Configure the storage settings according to your requirements. The default settings are typically fine for a basic Ubuntu server.
-
Add Tags (Optional):
- Click "Next: Add Tags" to add any tags if needed. Tags are useful for organizing and identifying instances.
-
Configure Security Group:
- Click "Next: Configure Security Group."
- Here, you define the rules that control traffic to your instance. At a minimum, you should allow SSH (port 22) for remote access.
-
Review and Launch:
- Click "Review and Launch."
- Review your instance configuration. If everything looks good, click "Launch."
-
Create a Key Pair:
- In the "Select an existing key pair or create a new key pair" window, choose to create a new key pair.
- Give your key pair a name, download it, and keep it in a secure location. This key pair is essential for SSH access to your instance.
-
Launch Instances:
- Click "Launch Instances" to start your Ubuntu server.
After the instance is launched, you can connect to it using SSH. Open a terminal on your local machine and use the following command:
ssh -i /path/to/your/key-pair.pem ubuntu@your_instance_ip
Replace /path/to/your/key-pair.pem
with the path to your downloaded key pair file and your_instance_ip
with the public IP address of your AWS instance.
This project is licensed under the MIT License. See the LICENSE file for details.