๐ 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 NGINX configuration
- Edit port number on which you want to run your website. I ran on port 3000
Now do
nginx -t
if it successfully test then run your website, If test failed like me then follow 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 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
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
- Go in Security and edit inbound rule
- Add rule > custom TCP > port range > anywhere IPv4 > save rules
- Copy your IPv4 address & paste it on google
- Website runs successfully
Thanks for reading to the end; I hope you gained some knowledge.โค๏ธ๐