for keeping the cat inside.
Cats are notorious for liking to explore and roam, especially males. Some seem to have an extra dose of that trait, or to just automatically rebel against any kind of containment, even inside a house or apartment. Even in rural areas, going outdoors can be risky for them, depending on what predators are in the area.
You can distract him from the door by tossing a treat or favorite toy in the opposite direction. Putting up a barrier in the doorway would present problems for you in coming and going.
Strengthening your bond with him and having enough entertainment (cat trees, toys, cat videos) to satisfy his need for attention and challenges might help to deter his interest in checking out the rest of the world.
Part of the effort to get out is the cat's hunting instincts. Maybe you can provide activities that let him use hunting skills indoors, like searching, stalking, ambushing, and getting food at the end. Hide some treats in odd places for him to sniff out and "capture." Play hide and seek games with him by peeking around a corner or piece of furniture at him, then backing out of sight a few times. Every cat that I've had could not resist coming after me when I did that. When she was younger, my current cat loved to find me when I hid somewhere and made a sound to get her started looking. She took it to the next level herself by hiding after she found me so that I had to find her. You might feel silly playing cat games, but it's good for the cat.
Mine also loves to hide in her tunnels and pounce me as I walk by. Getting enough hunting play might reduce the urge to go outdoors to hunt.
If it is too difficult to keep him inside, a last resort might be finding a home for him that would be safer and getting another cat for yourself.