4

I am unable to reach EC2 instance after installing NGINX on that EC2 instance didn't get why this happen I just run below commands:

sudo apt update
sudo apt install nginx
sudo ufw app list
sudo ufw enable
sudo ufw allow 'Nginx HTTP'
sudo ufw status

before installing NGINX i am able to take SSH connection of EC2 but after doing this I am not reach to EC2 i cross check everything

SG Inbounds has enable 22 port [trying with all of three MyIp,Custom,Anywhere], VPC has internet gateway which is properly bind

is there anything that i left? or

 "sudo ufw enable" 

command run on my EC2 is creates the issue

Kiwi Rupela
  • 2,238
  • 5
  • 24
  • 44

2 Answers2

12
  1. Stop the running EC2 instance
  2. Detach its /dev/sda1 volume
  3. Start another EC2 instance, it should be on the same subnet
  4. Attach volume to the new micro instance, as /dev/xvdf
  5. SSH to the new instance and mount the volume to /mnt/tmp

    sudo fdisk -l # check volumes and find the volume we wanna mount, in my case it's /dev/xvdf1 sudo mkdir /mnt/tmp sudo mount /dev/xvdf1 /mnt/tmp

  6. Disable UFW by setting ENABLED=no in /mnt/tmp/etc/ufw/ufw.conf

    cd sudo nano /mnt/tmp/etc/ufw/ufw.conf

  7. Exit

  8. Terminate the new instance
  9. Detach the volume from it
  10. Attach volume back to the main instance as /dev/sda1 Start the main instance
  11. Login as before

  12. Enable ssh connections

    sudo ufw allow ssh sudo ufw enable

Kudos to: https://stackoverflow.com/a/49432706

Mohamad Al Mdfaa
  • 985
  • 1
  • 11
  • 16
3

You should allow SSH connections before enabling the firewall so;

Execute

sudo ufw allow ssh

Before

sudo ufw enable
Yarimadam
  • 1,128
  • 9
  • 12
  • I am unable to reach EC2 so now how can I allow ssh is there any other way and is it the issue of ufw i am not sure about this? – Kiwi Rupela Mar 06 '19 at 13:01
  • i'm not sure aws provides console access. if it doesn't you can destroy and recreate the ec2 instance. – Yarimadam Mar 06 '19 at 14:43