How to Install Nginx on Amazon Linux 2023 (EC2)
To install Nginx on Amazon Linux 2023, connect to the EC2 instance and run sudo yum install -y nginx, then sudo service nginx start and sudo systemctl enable nginx. Allow HTTP (TCP port 80) in the instance's security group and open http://<PUBLIC_IP> in a browser to see the Nginx welcome page. The default web root on Amazon Linux 2023 is /usr/share/nginx/html.
Hello friends! In this guide we will install Nginx on an Amazon Linux 2023 EC2 server and open our first web page in the browser. Now a little story: suppose I want to propose to my GF. So I make a small static website – "Will you be my Valentine?" on index.html – host it on EC2 with Nginx, and then simply send her the link. Come on, type every command along with me.
नमस्कार मित्रांनो! या गाइड मध्ये आपण Amazon Linux 2023 च्या EC2 सर्व्हर वर Nginx install करून पहिलं वेब पेज ब्राउझर मध्ये उघडणार आहोत. आता एक गोष्ट: समजा मला माझ्या GF ला प्रपोज करायचं आहे. म्हणून मी एक छोटी static वेबसाइट बनवतो – index.html वर "Will you be my Valentine?" – ती EC2 वर Nginx ने host करतो, आणि मग तिला फक्त लिंक पाठवतो. चला, प्रत्येक कमांड माझ्या सोबत टाइप करा.
नमस्कार दोस्तों! इस गाइड में हम Amazon Linux 2023 के EC2 सर्वर पर Nginx install करके पहला वेब पेज ब्राउज़र में खोलेंगे. अब एक कहानी: मान लो मुझे अपनी GF को प्रपोज़ करना है. तो मैं एक छोटी static वेबसाइट बनाता हूँ – index.html पर "Will you be my Valentine?" – उसे EC2 पर Nginx से host करता हूँ, और फिर उसे बस लिंक भेज देता हूँ. चलो, हर कमांड मेरे साथ टाइप करो.
Quick answer
On an Amazon Linux 2023 EC2 instance, run these four commands, allow HTTP (TCP port 80) in the instance's security group, and open http://<PUBLIC_IP> in your browser:
sudo yum install -y nginx
sudo service nginx start
sudo systemctl enable nginx
curl -I http://localhost # expect HTTP/1.1 200 OK
What do I need before installing Nginx?
- An EC2 instance running Amazon Linux 2023 with a public IP. New to this? Follow How to Launch an EC2 Instance in AWS.
- An SSH session on that instance. See How to SSH into EC2 from Windows, Mac and Linux.
- About 10 minutes. Every command below is copy-paste ready; do not type the
#comments.
How does a web request reach Nginx on EC2?
The browser on a laptop or mobile sends a Request over the internet. The security group lets it in on port 80, Nginx on EC2 answers with the page, and the Response travels back.
लॅपटॉप किंवा मोबाइल वरचा ब्राउझर इंटरनेट वरून Request पाठवतो. Security group ती port 80 वर आत येऊ देतो, EC2 वरचा Nginx पेज देऊन उत्तर देतो, आणि Response परत येतो.
लैपटॉप या मोबाइल का ब्राउज़र इंटरनेट से Request भेजता है. Security group उसे port 80 पर अंदर आने देता है, EC2 पर Nginx पेज के साथ जवाब देता है, और Response वापस आता है.
How do I install Nginx on Amazon Linux 2023?
Step 1 — Launch the instance and connect (short version)
In the EC2 console click Launch instance, choose the Amazon Linux 2023 AMI, a free-tier eligible type such as t3.micro or t2.micro, a key pair, and a security group with SSH 22 from My IP and HTTP 80 / HTTPS 443 from Anywhere-IPv4. Keep Auto-assign public IP enabled. When the instance shows Running and 2/2 checks passed, connect from your laptop:
chmod 400 mykey.pem
ssh -i mykey.pem ec2-user@<PUBLIC_IP>
The login user on Amazon Linux is ec2-user.
Step 2 — Allow HTTP (port 80) in the security group
The security group is the firewall in front of your instance. For a website it needs these inbound rules:
| Type | Protocol | Port | Source | Why |
|---|---|---|---|---|
| SSH | TCP | 22 | My IP | Only you can log in |
| HTTP | TCP | 80 | Anywhere-IPv4 0.0.0.0/0 |
Website |
| HTTPS | TCP | 443 | Anywhere-IPv4 0.0.0.0/0 |
Secure website (later) |
If your instance was launched without port 80, open the instance's security group from the Security tab and add the HTTP rule (details: How to Open Port 80 and 443 in an EC2 Security Group). Never open port 22 to 0.0.0.0/0.
Step 3 — Install Nginx
sudo yum install -y nginx
On Amazon Linux 2023 the package and the service are both called nginx. (On the older Amazon Linux 2 the command is sudo amazon-linux-extras install -y nginx1; everything else in this guide is the same.)
Step 4 — Start Nginx and enable it at boot
On Amazon Linux 2023 the service does not start by itself after install, so start it now and enable it for every reboot:
sudo service nginx start
sudo systemctl enable nginx
sudo service nginx status # look for "active (running)"
Step 5 — Check that Nginx works
First test from inside the server, then from your browser:
sudo nginx -t # test configuration syntax
curl -I http://localhost # expect HTTP/1.1 200 OK
Now open http://<PUBLIC_IP> in your browser — note http, not https. You should see the Nginx welcome page. Server ready! 🎉
Ravindra Bagale's Tip
💡 If the page doesn't open in the browser, don't change the config straight away. First run curl -I http://localhost on the server itself. If you get 200 there but not in the browser, the problem is not in Nginx – it is outside: port 80 in the security group, typing https://, or the wrong IP. Inside and outside – always keep these two tests separate.
Ravindra Bagale's Tip – मराठी
💡 पेज ब्राउझर मध्ये उघडलं नाही तर लगेच config बदलू नका. आधी सर्व्हर वरच curl -I http://localhost चालवा. इथे 200 आला पण ब्राउझर मध्ये नाही, तर प्रॉब्लेम Nginx मध्ये नाही – बाहेर आहे: security group मध्ये port 80, https:// टाइप केलं, किंवा चुकीचा IP. आतून आणि बाहेरून – या दोन टेस्ट नेहमी वेगळ्या करा.
Ravindra Bagale's Tip – हिंदी
💡 पेज ब्राउज़र में नहीं खुला तो तुरंत config मत बदलो. पहले सर्वर पर ही curl -I http://localhost चलाओ. यहाँ 200 आया पर ब्राउज़र में नहीं, तो प्रॉब्लम Nginx में नहीं – बाहर है: security group में port 80, https:// टाइप किया, या गलत IP. अंदर से और बाहर से – ये दो टेस्ट हमेशा अलग करो.
Step 6 — Replace the default page with your own
On Amazon Linux 2023 the default web root of Nginx is /usr/share/nginx/html. For our example – a one-page proposal site – write a simple index.html there:
ls /usr/share/nginx/html
sudo tee /usr/share/nginx/html/index.html > /dev/null <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>A question for you</title></head>
<body style="text-align:center;font-family:sans-serif;padding-top:80px">
<h1>Will you be my Valentine? ❤️</h1>
<p>Made by me, hosted on AWS EC2 with Nginx.</p>
</body>
</html>
EOF
curl http://localhost
Refresh http://<PUBLIC_IP> on your phone and your own page appears – that is the link you send. The same steps work for any static site, for example a portfolio or a small shop page. Replacing the default test page before a server goes on the internet is also good security: default pages make a server easy to identify.
For a real site in its own folder with its own server block (for example /var/www/mysite), follow How to Host a Static Website on EC2 with Nginx.
Step 7 — Firewall, port and log checks
Amazon Linux 2023 has no host firewall active by default, so the AWS security group alone controls access. These commands answer the usual questions:
sudo ss -tlnp | grep :80 # is Nginx listening on port 80?
sudo nginx -t && sudo service nginx reload # apply a config change safely
sudo tail -n 20 /var/log/nginx/error.log # read the latest errors
On CentOS Stream 9, firewalld may be running and must allow HTTP as well; on Ubuntu the install command is sudo apt install -y nginx. See the quick reference for each OS.
Ravindra Bagale's Tip
Make sudo nginx -t && sudo service nginx reload a habit. If the -t test fails, the reload does not happen, so one typo cannot take your site down. Don't restart blindly; when an error appears, read the error log first – the file name and line number are right there.
Ravindra Bagale's Tip – मराठी
sudo nginx -t && sudo service nginx reload ही एकच सवय लावा. -t टेस्ट फेल झाली तर reload होत नाही, म्हणून एका टायपो मुळे तुमची साइट बंद पडत नाही. आंधळेपणाने restart करू नका, आणि error आला की आधी error log वाचा – फाइलचं नाव आणि लाइन नंबर तिथेच मिळतो.
Ravindra Bagale's Tip – हिंदी
sudo nginx -t && sudo service nginx reload की एक ही आदत बनाओ. -t टेस्ट फेल हुआ तो reload नहीं होता, इसलिए एक टाइपो से आपकी साइट बंद नहीं पड़ती. आँख बंद करके restart मत करो, और error आए तो पहले error log पढ़ो – फ़ाइल का नाम और लाइन नंबर वहीं मिलता है.
How do I fix common Nginx errors on EC2?
Ghabru naka 😅 — every beginner meets these. Find your symptom in the first column:
| Symptom | Likely cause | Fix |
|---|---|---|
| Browser spins, then timeout | Port 80 missing in the security group; no public IP; typed https:// |
Add inbound HTTP 80 from 0.0.0.0/0; check the public IP; use http:// |
| Connection refused | Nginx is not running | sudo service nginx start, then sudo service nginx status; sudo ss -tlnp |
| Still shows the welcome page | Your file is not in the web root | Write index.html into /usr/share/nginx/html; ls /usr/share/nginx/html |
bind() to 0.0.0.0:80 failed (98: Address in use) |
Apache or another Nginx already uses port 80 | sudo ss -tlnp | grep :80; stop the other server (sudo service httpd stop) |
| Config change has no effect | Forgot to reload, or a syntax error | sudo nginx -t && sudo service nginx reload |
| Site broke after stop/start | The auto-assigned public IP changed | Use the new IP, or attach an Elastic IP |
Learn it properly
This guide is the short path. The free AWS course explains every step in depth, with labs:
Got it? Install, start, enable, curl – and port 80 in the security group. That's all! Your first website is live now – just send the link and wait for the answer. If you want to add a domain and HTTPS next, continue with the next lessons of the course.
समजलं का? Install, start, enable, curl – आणि security group मध्ये port 80. एवढंच! तुमची पहिली वेबसाइट आता लाइव्ह आहे – आता फक्त लिंक पाठवा आणि उत्तराची वाट बघा. पुढे डोमेन आणि HTTPS लावायचं असेल तर कोर्स मधले पुढचे लेसन्स करा.
समझ आया? Install, start, enable, curl – और security group में port 80. बस इतना ही! आपकी पहली वेबसाइट अब लाइव है – अब बस लिंक भेजो और जवाब का इंतज़ार करो. आगे डोमेन और HTTPS लगाना हो तो कोर्स के अगले लेसन करो.
Frequently asked questions
How do I install Nginx on Amazon Linux 2023?
Run sudo yum install -y nginx, then sudo service nginx start to start it now and sudo systemctl enable nginx so that it starts at every boot.
How do I check that Nginx is working?
On the server run sudo service nginx status and curl -I http://localhost; you should see HTTP/1.1 200 OK. sudo nginx -t tests the configuration syntax.
Why does the Nginx page not open in my browser?
Almost always one of: the security group does not allow port 80 from 0.0.0.0/0, you typed https:// but no TLS is configured, Nginx is not running, or the instance has no public IP.
Where are the default website files for Nginx?
On Amazon Linux 2023 the default web root is /usr/share/nginx/html. Put your index.html there.
How do I install Nginx on Amazon Linux 2?
On the older Amazon Linux 2 use sudo amazon-linux-extras install -y nginx1. Everything else (paths, service names) is the same.
How do I install Apache instead of Nginx?
Run sudo yum install -y httpd, sudo service httpd start and sudo systemctl enable httpd, then check with sudo apachectl configtest (expect "Syntax OK").