The black soldier fly Hermetia illucens is used for the bioconversion of organic waste into feed for livestock and aquaculture, and is economically among the most important farmed insects in the world. The larvae can be fed on agricultural waste and even liquid manure, resulting in highly unpredictable pathogen levels and dietary conditions. Here we show that H. illucens larvae express a remarkably expanded spectrum of antimicrobial peptides (AMPs), many of which are induced by feeding on a diet containing high bacterial loads. The addition of sulfonated lignin, cellulose, chitin, brewer's grains or sunflower oil revealed the diet-dependent expression profiles of AMPs in the larvae. The highest number of AMPs and the highest levels of AMP expression were induced by feeding larvae on diets supplemented with protein or sunflower oil. Strikingly, the diet-dependent expression of AMPs translated into diet-dependent profiles of inhibitory activities against a spectrum of bacteria, providing an intriguing example for the emerging field of nutritional immunology. We postulate that the fine-tuned expression of the expanded AMP repertoire mediates the adaptation of the gut microbiota to the digestion of unusual diets, and this feature could facilitate the use of H. illucens for the bioconversion of organic waste.