Create two security groups:
- First security group called something like"ALBSecurityGroup" allows http(s) ingress from 0.0.0.0/0. Put the ALB in that. The ALB should be in a public subnet with public IPs.
- Second security group called something like "ServerSecurityGroup" allows http(s) ingress from "ALBSecurityGroup". Put the servers in that. The servers should ideally be in a private subnet with no public IPs assigned.
If you try to specify egress security groups you can get yourself into circular dependencies. There's ways around it but easiest for someone new to AWS to just leave the egress open, unless you need egress restricted.
Outside of AWS you can do this with IPTables, but might as well make use of AWS features. I do something similar in that I prevent direct access to my web server, I only whitelist my static home IP and CloudFlare CDN IP ranges.