Day 34: Serve a simple static website on NGINX.

Day 34: Serve a simple static website on NGINX.

#90daysofdevops

ยท

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 NGINX configuration

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

  1. Now do nginx -t if it successfully test then run your website, If test failed like me then follow 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 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 command is commonly used in modern Linux distributions that use systemd as their init system.

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

  1. Go in Security and edit inbound rule

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

  1. Copy your IPv4 address & paste it on google

  1. Website runs successfully


Thanks for reading to the end; I hope you gained some knowledge.โค๏ธ๐Ÿ™Œ

Linkedln

Twitter

Github

ย