Vitamin D plays an important role in the immune system, and there is some evidence that higher vitamin D levels help people to prevent upper respiratory tract infections, see here:
There have been multiple cross-sectional studies associating lower levels of vitamin D with increased infection. One report studied almost 19,000 subjects between 1988 and 1994. Individuals with lower vitamin D levels (<30 ng/ml) were more likely to self-report a recent upper respiratory tract infection than those with sufficient levels, even after adjusting for variables including season, age, gender, body mass and race[8]. Vitamin D levels fluctuate over the year. Although rates of seasonal infections varied, and were lowest in the summer and highest in the winter, the association of lower serum vitamin D levels and infection held during each season. Another cross-sectional study of 800 military recruits in Finland stratified men by serum vitamin D levels[9]. Those recruits with lower vitamin D levels lost significantly more days from active duty secondary to upper respiratory infections than recruits with higher vitamin D levels (above 40 nmol). There have been a number of other cross-sectional studies looking at vitamin D levels and rates of influenza [10] as well as other infections including bacterial vaginosis[11] and HIV[12-13]. All have reported an association of lower vitamin D levels and increased rates of infection.
The basic mechanisms that are known can be summarized as follows:
The immunomodulatory effects of 1,25(OH)2D3. 1,25(OH)2D3 targets different players of the innate and adaptive immune compartment. 1,25(OH)2D3 stimulates innate immune responses by enhancing the chemotactic and phagocytotic responses of macrophages as well as the production of antimicrobial proteins such as cathelicidin. On the other hand, 1,25(OH)2D3 also modulates adaptive immunity. At the level of the APC (like the DC), 1,25(OH)2D3 inhibits the surface expression of MHC-II-complexed antigen and of co-stimulatory molecules, in addition to production of the cytokines IL-12 and IL-23, thereby indirectly shifting the polarization of T cells from a Th1 and Th17 phenotype towards a Th2 phenotype. In addition, 1,25(OH)2D3 directly affects T cell responses, by inhibiting the production of Th1 cytokines (IL-2 and IFN-γ) and Th17 cytokines (IL-17 and IL-21), and by stimulating Th2 cytokine production (IL-4). Moreover, 1,25(OH)2D3 favors Treg cell development via modulation of DCs and by directly targeting T cells. Finally, 1,25(OH)2D3 blocks plasma cell differentiation, IgG and IgM production and B cell proliferation.
In addition to this, vitamin D is needed to build muscle, heavy exercise will deplete vitamin D levels, potentially compromising your immune system:
Our findings support our hypothesis. Analysis of our results showed that vitamin D levels are associated with neuromuscular performance and aerobic capacity in professional soccer players. Notably, to the best of our knowledge, for the first time our study provides evidence of a linear relationship between vitamin D serum levels, not only with jumping performance, but also with VO2max and speed in non-supplemented soccer players. In addition, we have found that even the short off-season period of reduced training stress had a boosting effect on vitamin D levels. Interestingly, this increase in vitamin D levels was evident in parallel to a reduction in aerobic and neuromuscular performance parameters. The latter finding strengthens the well-documented concept that training plays the principal role for exercise adaptations and improvements in exercise performance, whereas all other parameters including vitamin D play a supportive role.
I make sure I get about 7000 IU of vitamin D per day, and I keep my calcidiol level at about 200 nmol/l. In the summer I adjust the intake of vitamin D supplements to take into account the amount I get from the Sun, in the winter I get the entire dose of 7000 IU/day from supplements (I then take 10,000 IU/day, 5 times per week). Note that such doses and calcidiol levels are safe.
I don't exercise in a gym, I only exercise outside. This helps to build immunity against cold viruses early on when they are still evolving to become next winter's scourge. When you run, your lungs filter the air less, allowing viruses to enter your body more easily. Also, you are inhaling an enormous amount of air up to ten times more per unit time compared to being in rest. Chances are then that your immune system will already have encounter the cold viruses that will later mutate a bit and then make many people ill.