SSH access works, but "The connection was reset" on ipV4 Public in browser

0

I launched an EC2 instance, am able to SSH using Mac Terminal command like this:
ssh -i "mykeyfile.pem" ec2-user@ec2-54-203-231-30.us-west-2.compute.amazonaws.com

I was also able to connect using FileZilla and upload a file (index.html). I can see this file using the "ls" command in Terminal.

Problem: Putting the ipV4 Public IP address in the Chrome or Firefox address bar, I get: "This site can’t be reached. The connection was reset."

I have added various inbound rules, including for HTTP port 80, source
0.0.0.0/0 and ::/0.

Also enabled ICMP. Ping to the ipV4 Public IP address times out.

Instance ID: i-02bf3badc0bbb5613
Instance Type: t2.micro
Availability Zone: us-west-2a
Instance State: running
Status Checks: 2/2 checks passed
Alarm Status: None
Public DNS (IPv4): ec2-54-203-231-30.us-west-2.compute.amazonaws.com
IPv4 Public IP: 54.203.231.30
Launch Time: June 28, 2019 at 12:01:14 P

asked 5 years ago598 views
4 Answers
0
Accepted Answer

Hello it seems that apache is installed but not started.

To start apache you can try one of the following
sudo systemctl status httpd.service
/etc/init.d/httpd start

Then you can check with following:
netstat - na | grep 80 (to check if apache is responding on port 80)
ps - ef |grep httpd (to check if apache is running)

Please let me know if then it works

answered 5 years ago
0

Hello, if you checked the security groups then the connectivity is ok, you should check if in your ec2 instance is running a web server (i.e. apache).

First you can login with putty in your ec2 and run the following command
netstat -na | grep 80
if the command doesn't respond you should enbale or install a web server

You can install apache with the following commands:
sudo yum install httpd -y
then copy your index.html in /var/www/html/index.html
systemctl start httpd
systemctl enable httpd

Can you try and give me a feedback about the result?
Thanks

answered 5 years ago
0

Thank you @andreacavallieri for your assistance !

Using Mac Terminal, the netstat -na | grep 80 command did respond as follows:

udp6 0 0 fe80::fb:3eff:fe6b::546 :::*
unix 2 [ ACC ] STREAM LISTENING 9080 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 14880

Also got the following using yum info httpd

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Available Packages
Name : httpd
Arch : x86_64
Version : 2.4.39
Release : 1.amzn2.0.1
Size : 1.3 M
Repo : amzn2-core/2/x86_64
Summary : Apache HTTP Server
URL : https://httpd.apache.org/
License : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
: web server.

However, the httpd -V command yielded:
-bash: httpd: command not found

And rpm -qf /etc/httpd gave:
error: file /etc/httpd: No such file or directory

So I went ahead and installed Apache using sudo yum install httpd -y

That was successful.

Copied index.html to /var/www/html/

Then ran the following commands with the following results:

systemctl start httpd
Failed to start httpd.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status httpd.service' for details.

systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd.service(8)

systemctl enable httpd
Failed to execute operation: The name org.freedesktop.PolicyKit1 was not provided by any .service files

systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd.service(8)

httpd -v
Server version: Apache/2.4.39 ()
Server built: Apr 4 2019 18:09:28

Installed policykit using sudo install polkit

systemctl enable httpd
Asked for a password, and authentication failed as shown below:

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-unit-files ===
Authentication is required to manage system service or unit files.
Authenticating as: EC2 Default User (ec2-user)
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Failed to execute operation: Access denied

sudo got around the password problem:
sudo systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

And it would now appear that the web server is enabled though "dead".

systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:httpd.service(8)

http://54.203.231.30/ in the browser
still resulted in "This site can’t be reached The connection was reset."

So ...

sudo service httpd start
Redirecting to /bin/systemctl start httpd.service

systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-06-30 20:35:43 UTC; 14s ago
Docs: man:httpd.service(8)
Main PID: 9520 (httpd)
Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec"
CGroup: /system.slice/httpd.service
├─9520 /usr/sbin/httpd -DFOREGROUND
├─9521 /usr/sbin/httpd -DFOREGROUND
├─9522 /usr/sbin/httpd -DFOREGROUND
├─9523 /usr/sbin/httpd -DFOREGROUND
├─9524 /usr/sbin/httpd -DFOREGROUND
└─9525 /usr/sbin/httpd -DFOREGROUND

Jun 30 20:35:43 ip-172-31-40-8.us-west-2.compute.internal systemd[1]: Starting The Apache HTTP Server...
Jun 30 20:35:43 ip-172-31-40-8.us-west-2.compute.internal systemd[1]: Started The Apache HTTP Server.

Now http://54.203.231.30/ in the browser
gives the Apache test page!

Edited by: mikeh100 on Jun 30, 2019 1:37 PM

answered 5 years ago
0

Thank you @andreacavallieri !

It is working!!! Web page displays at http://54.203.231.30/

netstat - na | grep 80
unix 3 [ ] STREAM CONNECTED 133807
unix 3 [ ] STREAM CONNECTED 14880
unix 3 [ ] STREAM CONNECTED 133808
unix 2 [ ] DGRAM 133801

ps -ef |grep httpd
root 9520 1 0 20:35 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9521 9520 0 20:35 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9522 9520 0 20:35 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9523 9520 0 20:35 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9524 9520 0 20:35 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9525 9520 0 20:35 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9568 9520 0 20:37 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 9628 9520 0 20:45 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
ec2-user 9688 9407 0 20:57 pts/0 00:00:00 grep --color=auto httpd

answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions