Unable to connect to an EC2 windows instance on port 8080 - amazon-web-services

I've created a free tier EC2 instance on AWS. I've opened inbound connections to this instance through security group. On EC2 instance, I'm able to access wildfly server and see it running/listening on port 127.0.0.1:8080. When I run netstat -ab command on EC2 instance I can see services listening on above IP address/port number combination. Could you please help me connect to this instance from my own machine? Please let me know if I should provide any additional info that would help troubleshoot the problem. Thanks in advance.
I've opened below inbound ports-
80 tcp 0.0.0.0/0
8080 tcp 0.0.0.0/0
22 tcp 0.0.0.0/0
23 tcp 0.0.0.0/0
3389 tcp 0.0.0.0/0
443 tcp 0.0.0.0/0
-1 icmp 0.0.0.0/0

Your service listens 127.0.0.1 which is not your network interface. Configure to listen to your instances private ip (10.x..) or 0.0.0.0 (all) instead

Solved it with the help of this post: JBoss WildFly: Starts but can't connect?
I was almost there but had to change standalone.xml to listen to all ports as #Michel suggested. Below is my standalone.xml . Thank you all again for all the help.
Earlier standalone entry:
<interfaces>
<interface name="management">
<inet-address value="${jboss.bind.address.management:0.0.0.0}"/>
</interface>
<interface name="public">
<inet-address value="${jboss.bind.address:0.0.0.0}"/>
</interface>
<interface name="unsecure">
<inet-address value="${jboss.bind.address.unsecure:0.0.0.1}"/>
</interface>
</interfaces>
Changed above to this:
<interfaces>
<interface name="management">
<!-- Use the IPv4 wildcard address -->
<any-address/>
</interface>
<interface name="public">
<!-- Use the IPv4 wildcard address -->
<any-address/>
</interface>
<interface name="unsecure">
<!-- Use the IPv4 wildcard address -->
<any-address/>
</interface>
</interfaces>

Related

How to configure Fluentd forwarder to stream logs to loadbalancer connected to an EC2 instance

I currently have launched an EC2 instance with Fluentd installed, and using in_forward Input plugin to receive logs from the other services. On the other side, the service will be sending logs to the EC2 instance out_forward Buffered Output plugin. For better security,I would like to create a loadbalancer in front of the EC2 instance, how should I change the fluentd.conf?Should I just replace the EC2 instance IP with the loadbalancer's one, or other config is needed?Thanks!
My Current fluentd.conf
Forwarder
# fluentd/conf/fluent.conf
<source>
#type forward
port 24224
bind 0.0.0.0
</source>
<match *.**>
#type forward
transport tls
tls_cert_path /path/to/fluentd.crt
tls_verify hostname false
<server>
host <EC2_instane_IP>
port 24224
</server>
</match>
Receiver
<source>
#type forward
port 24224
bind "0.0.0.0"
<transport tls>
cert_path "/path/to/fluentd.crt"
private_key_path "/path/to/fluentd.key"
</transport>
</source>
<match *.**>
type elasticsearch
host "localhost"
port 9200
index_name "app"
type_name "log"
include_tag_key true
tag_key "#log_name"
logstash_format true
flush_interval 10s
<buffer>
flush_interval 10s
</buffer>
</match>
#jenny your configs shouldn't change much. The forwarders will use <Load_Balancer_DNS_Name> for host. You will need to configure a load balancer in AWS w/ a listener on 24224 that forwards traffic to a target group consisting of your ec2 instance(s).

aws ec2 ssh error: `ssh: connect to host x port 22: Operation timed out`

I'm trying to connect to a EC2 instance via SSH. When I try to connect to the instance, using ssh -i "test.pem" ec2-user#xx.xx.xx.xx I get the error: ssh: connect to host xx.xx.xx.xx port 22: Operation timed out.
EC2 instance config
Platform: Amazon Linux
AMI: ami-0841edc20334f9287
Instance type: t2.micro
Public IPv4: associated Elastic IPv4
EC2 instance associated VPC subnet config:
Route Table: (Destination - Target)
10.0.0.0/24 - local
0.0.0.0/0 - igw-...
ACL: (Type - Protocol - Port range - Source)
Inbound
SSH - TCP - 22 - 0.0.0.0/0
Outbound
HTTPS - TCP - 443 - 0.0.0.0/0
Security Groups: (Type - Protocol - Port range - Source)
Inbound
SSH - TCP - 22 - xx.x.xxx.xxx/xx (My IP)
Outbound
HTTPS - TCP - 443 - 0.0.0.0/0
Attempts:
Followed this AWS article (solution #3) in which they propose adding this script to the instance’s user data:
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type:
text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
iptables -F
service sshd restart
--//
Which resulted in the same error:
ssh: connect to host public.ip port 22: Operation timed out
Chaning ssh user:
ssh -i "test.pem" ec2-user#public.ip
ssh -i "test.pem" root#public.ip
Which resulted in the same error:
ssh: connect to host public.ip port 22: Operation timed out
I tried using my public subnet within the same VPC and I was able to connect to ec2 via ssh. When comparing the public and private subnets, the only difference was that the public subnet's NACL allowed all traffic inbound traffic.
Connecting with EC2 Instance Connect on the console resulted in a blank terminal window even after 10 minutes or so.
Your NACL has the inbound rules for ssh. you should also allow the return ssh traffic in the outbound NACL rules. Because the NACL's are stateless unlike the security groups.
In addition to that, you should also allow ephemeral port ranges for the inbound and outbound NACL rules. Ephemeral ports are random ports ranging between 1024 and 65535 that a client initiating the request chooses as the source ports.
NACL Ephemeral Ports
Try running the Reachability Analyzer in your aws console.
AWS console >> VPC >> Network analysis >> Reachability Analyzer
You can choose the source of analyzer as internet gateway and destination as your ec2 instance. Once you run the analyzer, it will tell you if the instance is reachable from you source (IGW in this case) and the interesting thing is, it will also give you the reason why it is not reachable which will help in further debugging the cause.

I can not access to the website with a public IP

I am setting up a new EC2 with Ubuntu, but I am getting a weird error and it is that I can not access to the public ip, it says refused connection.
My security group has these ports enabled:
HTTP TCP 80 0.0.0.0/0 -
HTTP TCP 80 ::/0 -
SSH TCP 22 0.0.0.0/0 -
SSH TCP 22 ::/0 -
My public is: http://3.16.154.123/
The EC2 interface is running, it's in green and that is the public ip which it gives me... so I wonder what is the problem? why can I not access to the public ip? why does it say refused connection? or more clear this error ERR_CONNECTION_REFUSED
Thanks.
telnet 3.16.154.123 22
Trying 3.16.154.123...
Connected to 3.16.154.123.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
^]
Your ssh is working as expected but on port 80 it fails.
telnet 3.16.154.123 80
Trying 3.16.154.123...
telnet: Unable to connect to remote host: Connection refused
Can you check if there is any service running on the host itself using telnet localhost 80 - If this works then it will be worth to check the NACL at the vpc level for any block on port 80.

tomcat on 8080 under ELB using ACM for SSL

Currently, I am trying to configure the https for one of my tomcat which is under ELB and for SSL certificate I have used aws certificate manager and pointed to the ELB.
My Elb listeners ports are
ELB port 80 ---> Instance port --> 8080
ELB port 443 --> Instance port --> 8080 with ACM certificate.
Is any configuration that needs to be in tomcat level or any method to run my site with https using ACM?
Your can put NGNIX in each tomcat instance , Nginx is super reliable and has the smallest footprint I ever seen in a serious web server.
Then in NGNIX Config
NGINX will rewrite all requests to the ELB calling the HTTPS port utilizing status 301.
server {
listen 80;
server_name myhost.com;
# add ssl settings
return 301 https://myhost.com$request_uri;
}
Tomcat Config:
Now you need to touch the server.xml configuration of Tomcat (located # $TOMCAT/conf/server.xml) .
<Connector scheme="https" secure="true" proxyPort="443"
port="8080" protocol="HTTP/1.1"
connectionTimeout="25000"
URIEncoding="UTF-8"
redirectPort="8443" />
Amazon Elastic Load Balancer:
You have to configure in the AWS ELB the following listeners.
HTTP 80 -> HTTP 80 (nginx)
HTTPS 443 -> HTTP 8080 (tomcat)
I hope this works for you.

How to configure HTTPS for Tomcat on AWS

I have an instance on AWS with Tomcat that works on 80 port.
My security groups has following configuration:
I did do configuration for Tomcat and keytool. On local machine it works and I can do https://localhost:8443, but how can I open HTTPS for port 8443 on AWS?
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/home/user/keytools/ssl"
keystorePass="123456"/>
you just change Connector port=443 it will work.