Host with Nginx—because configuring web servers is what every cybersecurity professional dreams of doing after hours 😎

Host with Nginx—because configuring web servers is what every cybersecurity professional dreams of doing after hours 😎

Step 1: Setting up Your Server - Welcome to SysAdmin Hell👽

So, I spilled all my secrets,confidential data here, but don’t worry! By the time you’re reading this, I’ve already hit the big red “delete/purge” button. It was all just for the blog, to show you the full drama of how things work from start to finish. Enjoy the show!

1.1 Choose and Install an Operating System:

  • Oh, the joy of picking an OS! Let's go with Ubuntu, because why not make life easy for once😉?
💡
sudo apt update # Update package lists because we all love waiting⏳.
💡
sudo apt upgrade -y # Upgrade everything. Why? Because outdated software is so last decade.

Step 2: Install Nginx - The Web Server That Loves to Serve🤪

2.1 Install Nginx:

💡
sudo apt install nginx -y # Install Nginx. Because who needs another web server to configure💻?

2.2 Start Nginx:

💡
sudo systemctl start nginx # Let's get this party started🎉.

2.3 Enable Nginx on boot:

💡
sudo systemctl enable nginx # Because manual starting is so 2005.

2.4 Verify Nginx is running:

💡
sudo systemctl status nginx # Check if it's whining or running smoothly🏃‍♂️.

Step 3: Using A Records with Cloudflare for SSL:

3.1 Setup in Cloudflare:

💡
Add Your Domain: First, add your domain to Cloudflare if you haven't already. Cloudflare will provide you with new nameservers to update at your registrar.

3.2 Create A Records:

  • Go to the DNS section in your Cloudflare dashboard.
  • Add or edit an A record for your domain. For example:
    • Name: test.ashishbutle.com or leave blank for the root domain
    • IPv4 address: Your server's public IP address
    • Proxy status: Orange cloud (to proxy through Cloudflare)
  • If you want to support www.yourdomain.com, create another A record:
    • Name: www
    • IPv4 address: Same as above
    • Proxy status: Orange cloud

3.3 SSL with Cloudflare:

  • Universal SSL: Cloudflare automatically provides and manages SSL certificates for your domain and its subdomains when you use the orange cloud (proxy). This means:
    • You don't need to manually set up SSL certificates on your server for Cloudflare to serve HTTPS.
    • Cloudflare will handle SSL handshakes, encrypting traffic between the visitor and Cloudflare.
  • Full or Full (Strict) SSL:
    • Go to SSL/TLS > Overview in your Cloudflare dashboard.
    • Set the SSL encryption mode to "Full" or "Full (Strict)" to ensure encryption between Cloudflare and your origin server as well.

Step 4: Configure Nginx - The True Art of Misconfiguration🎭

4.1 Create Directory for Your Blog:

💡
sudo mkdir -p /var/www/yourblog # Make a directory, because where else would you put your blog📁?

4.2 Upload Your Template🖼️:Where the Real Fun Begins😝

Now, put your blog files in there. Use SCP✂️ or any carrier pigeons🦅

Creating an index.html file with below code for testing. 

💡
sudo nano /var/www/yourblog/index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome to Your Nginx Server</title>
</head>
<body>
    <h1>Welcome!</h1>
    <p>Congratulations, you're no longer a noob in hosting and Nginx! This is your index page, served by your very own Nginx server.</p>
</body>
</html>

4.3 Set permissions:

💡
sudo chown -R $USER:$USER /var/www/yourblog # Give yourself permission. Congrats, you're now the proud owner of a directory✅!
💡
sudo chmod -R 755 /var/www/yourblog # Because 777 permissions are just asking for trouble😵‍💫.

4.4 Nginx Configuration:

💡
sudo nano /etc/nginx/sites-available/yourblog # Use nano because vi is too hard for me 😵‍💫 and some of us.

4.5 Here's where you'd paste your config, but let's just say:

server {
    listen 80;
    server_name test.ashishbutle.com www.test.ashishbutle.com;

    root /var/www/yourblog; # Where your blog lives.
    index index.html index.htm index.nginx-debian.html; # Default files to look for.


    location / {
        try_files $uri $uri/ =404; # Try to serve file, if not found, return 404.
    }

    # Logging, because you never make mistakes.
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
}

4.5 Link the config to sites-enabled:

💡
sudo ln -s /etc/nginx/sites-available/yourblog /etc/nginx/sites-enabled/ # Symlink because we love shortcuts🚀.

4.6 Test Nginx Configuration:

💡
sudo nginx -t # Test config because breaking things is fun⛓️‍💥.
💡
sudo systemctl reload nginx # Reload if it didn't break, sigh⛓️‍💥.

Step 6: Security - Because We All Know It's Optional😜

6.1 Firewall: 🔏

💡
1) AWS>>Security Groups>>Open HTTPS 443/80,
2) Oracle Cloud>>Security List>>Open HTTPS 443/80,
3) sudo ufw allow 'Nginx Full' # Allow Nginx through the firewall, because what's security without open ports?

6.2 Regular Updates:

Keep everything updated because outdated software is like an open invitation for hackers📩.

6.3 Logs:

💡
Check logs in /var/log/nginx/ because who doesn't love a good mystery🎁?


7 Conclusion

Now your blog is up, secured with HTTPS, and using your custom template. Remember, in cybersecurity, every day is a new adventure in finding out what you've missed. Keep your system updated, your certificates renewed, and your logs checked. Because in the world of cybersecurity, complacency is your real enemy.

Happy blogging, and may your server logs be ever in your favor!