How to block direct IP access?

Greetings from India.

I’m kind of a newbie when it comes to advanced server configuration. I would like to block access to my server directly through its public IP address.

The IP address allocated to me is dynamic. I want my server to return either ‘connection reset’ or ‘connection dropped’ error when trying to connect directly through its public IP, on both port 80 & port 443.

Thanks in advance.

Kindly help me with this. I’m still unable to figure it out.