Serve a simple static website on NGINX

๐ Introduction
In this blog, we'll configure NGINX to serve a simple static website
- First do
sudo apt update
to update packages
- Then, install nginx on your EC2
sudo apt install nginx
- Create an index.html file in var/www/html to make it the main page of your website on the server.
- Edit the NGINX configuration
- Edit the port number on which you want to run your website. I ran on port 3000
Now do
nginx -t
If it successfully tests, then run your website. If the test failed, like me, then follow the given stepsIf no error occurs and the test is successful, proceed from point number 10. This instruction is for those who encountered an error.
- After getting an error type command
sudo chmod 644 /var/log/nginx/error.log
- Still getting error type
sudo chown www-data:www-data /var/log/nginx/error.log
&
sudo chmod 755 /run
- 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
- Go to Security and edit the inbound rule
- Add rule > custom TCP > port range > anywhere IPv4 > save rules
- Copy your IPv4 address & paste it on Google
- The website runs successfully
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!