Immunity and nutrition are two essential modulators of individual fitness. However, while the implications of immune function and nutrition on an individual's lifespan and reproduction are well established, the interplay between feeding behaviour, infection and immune function remains poorly understood. Asking how ecological and physiological factors affect immune responses and resistance to infections is a central theme of eco-immunology. In this study, we used the fruit fly, Drosophila melanogaster, to investigate how infection through septic injury modulates nutritional intake and how macronutrient balance affects survival to infection by the pathogenic Gram-positive bacterium Micrococcus luteus. Our results show that infected flies maintain carbohydrate intake, but reduce protein intake, thereby shifting from a protein-to-carbohydrate (P:C) ratio of ~1:4 to ~1:10 relative to non-infected and sham-infected flies. Strikingly, the proportion of flies dying after M. luteus infection was significantly lower when flies were fed a low-P high-C diet, revealing that flies shift their macronutrient intake as means of nutritional self-medication against bacterial infection. These results are likely due to the effects of the macronutrient balance on the regulation of the constitutive expression of innate immune genes, as a low-P high-C diet was linked to an upregulation in the expression of key antimicrobial peptides. Together, our results reveal the intricate relationship between macronutrient intake and resistance to infection and integrate the molecular cross-talk between metabolic and immune pathways into the framework of nutritional immunology.