Problem: "Port 80: Connection Refused" on Amazon Lightsail – Web Server Running but Not Accessible


Problem: "Port 80: Connection Refused" on Amazon Lightsail – Web Server Running but Not Accessible

Bash
$ curl -I http://54.123.45.67
curl: (7) Failed to connect to 54.123.45.67 port 80: Connection refused

Issue:

Your web server is running on Amazon Lightsail, but it is not accessible via HTTP (port 80). This can happen due to:

  • Firewall Rules Blocking Port 80 – Lightsail has port-based security groups, and port 80 might be closed.
  • Web Server Not Running – Apache/Nginx may have crashed or is not started.
  • Wrong Public IP Used – Your instance might not have a static IP attached, causing it to change after reboot.
  • Software Firewall (UFW/IPTables) Blocking Traffic – Even if Lightsail allows traffic, your instance OS firewall might block port 80.

Fix: Open Port 80 in Lightsail, Verify Web Server, and Ensure Public IP Stability

Bash
# Step 1: Check if the instance is running
$ aws lightsail get-instances \
    --query "instances[].{Name:name, State:state.name, PublicIP:publicIpAddress}" \
    --output table

--------------------------------
|        GetInstances         |
--------------------------------
|  Name         |  State     |  PublicIP      |
--------------------------------
|  WebServer    |  Stopped   |  54.123.45.67  |
--------------------------------

# If the instance is "stopped" or "stopping," restart it:
$ aws lightsail start-instance \
    --instance-name "WebServer"

# Confirm the instance is now running:
$ aws lightsail get-instances \
    --query "instances[].{Name:name, State:state.name, PublicIP:publicIpAddress}" \
    --output table

--------------------------------
|        GetInstances         |
--------------------------------
|  Name         |  State     |  PublicIP      |
--------------------------------
|  WebServer    |  Running   |  54.123.45.67  |
--------------------------------

# Step 2: Check if port 80 is open in Lightsail's firewall
$ aws lightsail get-instance-port-states \
    --instance-name "WebServer"

{
    "portStates": [
        {
            "fromPort": 22,
            "toPort": 22,
            "protocol": "tcp",
            "state": "open"
        },
        {
            "fromPort": 80,
            "toPort": 80,
            "protocol": "tcp",
            "state": "closed"
        }
    ]
}

# Step 3: If port 80 is closed, open it
$ aws lightsail open-instance-public-ports \
    --instance-name "WebServer" \
    --port-info fromPort=80,toPort=80,protocol=TCP

# Step 3.1: Verify that port 80 is now open
$ aws lightsail get-instance-port-states \
    --instance-name "WebServer"

# Step 4: Ensure Apache/Nginx is running
$ systemctl status apache2  # For Ubuntu/Debian
$ systemctl status httpd    # For Amazon Linux/CentOS

# If the service is inactive, start it:
$ sudo systemctl start apache2  # For Ubuntu/Debian
$ sudo systemctl start httpd    # For Amazon Linux/CentOS

# Step 5: If using UFW, ensure port 80 is allowed
$ sudo ufw allow 80/tcp
$ sudo ufw status

# Step 6: Check if your public IP is static (avoiding changes on reboot)
$ aws lightsail get-instance \
    --instance-name "WebServer" \
    --query "instance.publicIpAddress"

# If your public IP keeps changing, attach a static IP:
$ aws lightsail allocate-static-ip \
    --static-ip-name "MyStaticIP"

$ aws lightsail attach-static-ip \
    --static-ip-name "MyStaticIP" \
    --instance-name "WebServer"

Need AWS Expertise?

If you're looking for guidance on Amazon Lightsail or any cloud challenges, feel free to reach out! We'd love to help you tackle your Lightsail projects. 🚀

Email us at: info@pacificw.com


Image: Gemini

Comments

Popular posts from this blog

The New ChatGPT Reason Feature: What It Is and Why You Should Use It

Raspberry Pi Connect vs. RealVNC: A Comprehensive Comparison

The Reasoning Chain in DeepSeek R1: A Glimpse into AI’s Thought Process