1. Introduction
This documentation outlines the steps taken to set up and configure NGINX on a fresh Ubuntu server. The goal was to create a functional web server capable of serving a simple HTML page.
2. Prerequisites
- An AWS EC2 instance running Ubuntu 22.04 LTS.
- SSH access to the server using a .pem key pair.
- Basic familiarity with the Linux command line.
3. Step-by-Step Process
Step 1: Provision the Ubuntu Server
- Create an EC2 Instance:
Log in to the AWS Management Console.
-
Launch an EC2 instance with the following specifications:
- AMI: Ubuntu Server 22.04 LTS
- Instance Type: t2.micro (free tier eligible)
- Storage: 8 GB (default)
Configure the security group to allow SSH (port 22) and HTTP (port 80) traffic.
Download the .pem key pair for SSH access.
2. Connect to the Server:
- Use SSH to connect to the server:
ssh -i /path/to/your-key.pem ubuntu@your_server_public_ip
Step 2: Install NGINX
1. Update the package list:
sudo apt update
2. Install NGINX:
sudo apt install nginx
3. Verify the installation:
nginx -v
Step 3: Configure NGINX
1. Start and enable NGINX:
sudo systemctl start nginx
sudo systemctl enable nginx
2. Check the status of NGINX:
sudo systemctl status nginx
3. Open the default NGINX configuration file:
sudo nano /etc/nginx/sites-available/default
4. Modify the configuration to serve a simple HTML page:
Update the
root
directive to/var/www/html
.Ensure the
index
directive includesindex.html
.
Example configuration:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
5. Save and exit the editor (Ctrl+O
, Enter, Ctrl+X
)
Step 4: Create a Simple HTML Page
-
Create the HTML directory:
sudo mkdir -p /var/www/html
-
Create an
index.html
file:
sudo nano /var/www/html/index.html
-
Add the following HTML content:
<!DOCTYPE html> <html> <head> <title>Welcome to My Server!</title> </head> <body> <p>Welcome to DevOps Stage 0 - Felix Mukah/Felix Mukah</p> </body> </html>
Save and exit the editor.
Step 5: Test the Configuration
-
Test the NGINX configuration for syntax errors:
sudo nginx -t
-
Reload NGINX to apply the changes:
sudo systemctl reload nginx
Open a web browser and navigate to your server’s public IP address:
http://your_server_public_ip
You should see the HTML page you created.
4. Verification
NGINX Status: Confirmed NGINX is running using sudo systemctl status nginx.
Web Page: Verified the HTML page is accessible via the server’s public IP.
5. Challenges and Solutions
Challenge: Initially, the .pem file was not recognized by PuTTYgen on Windows.
Solution: Converted the .pem file to .ppk using PuTTYgen and successfully connected to the server.
6. Conclusion
This project successfully demonstrated the setup and configuration of NGINX on a fresh Ubuntu server. The server is now capable of serving a simple HTML page over HTTP. This foundational knowledge can be expanded to host dynamic websites, implement SSL/TLS, and explore advanced NGINX features.
7. References
Top comments (0)