Serve a simple static website on NGINX

AshwinAshwin
2 min read

๐Ÿš€ Introduction

In this blog, we'll configure NGINX to serve a simple static website


  1. First do sudo apt update to update packages

  1. Then, install nginx on your EC2

sudo apt install nginx
  1. Create an index.html file in var/www/html to make it the main page of your website on the server.

  1. Edit the NGINX configuration

  1. Edit the port number on which you want to run your website. I ran on port 3000

  1. Now do nginx -t If it successfully tests, then run your website. If the test failed, like me, then follow the given steps

    If no error occurs and the test is successful, proceed from point number 10. This instruction is for those who encountered an error.

  1. After getting an error type command sudo chmod 644 /var/log/nginx/error.log

  1. Still getting error type sudo chown www-data:www-data /var/log/nginx/error.log &

sudo chmod 755 /run

  1. Now, restart your nginx service by typing the following command:

sudo service nginx restart It tells the system to restart the Nginx service. This syntax is more traditional and is commonly found in older Linux distributions.

sudo systemctl restart nginx It instructs the system to restart the Nginx service. The systemctl The command is commonly used in modern Linux distributions that use systemd as their init system.

Now type sudo nginx -t and test whether the configuration file runs successfully or not

  1. Go to Security and edit the inbound rule

  1. Add rule > custom TCP > port range > anywhere IPv4 > save rules

  1. Copy your IPv4 address & paste it on Google

  1. The website runs successfully

0
Subscribe to my newsletter

Read articles from Ashwin directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashwin
Ashwin

I'm a DevOps magician, conjuring automation spells and banishing manual headaches. With Jenkins, Docker, and Kubernetes in my toolkit, I turn deployment chaos into a comedy show. Let's sprinkle some DevOps magic and watch the sparks fly!