Put trash in bags and tie the bags shut. Spray the can when you put the trash out with bleach or ammonia diluted in water. Don’t overfill cans such that the lid won’t fully shut.
Push the lid on as tightly as possible. To deter large pests such as raccoons or dogs, place a heavy rock on top or keep the lid on with a bungee cord or piece of rope so that even tipping it over won’t spill the contents. Or use a trash can designed so the handles push up and lock the lid in place.
Place petroleum jelly under the lip of the trash can to keep crawling pests from getting inside.
Keep your garbage can clean. Wash it out as needed with a soapy solution with added ammonia or vinegar.