Connectivity issue in Filebeat and kafka server

I'm using filebeat to send logs to Kafka topic. The source system is a server with an IP that is not static and it's an on-prem server. The destination server is a AWS Ec2 instance. Currently I'm not able to make connectivity with both these servers.
Is there a way to create this connectivity in a secure way?

What is the issue? You didn't explain the problem.

I'm outputting logs to kafka topic which is running on a AWS ec2 instance, the source server is a on-prem server. Filebeat is able to establish connection but nothing is being written on the kafka topic. I have exposed the kafka server through nginx reverse proxy. Is this not right way to do it?