Of all the body cavities
in contact with the outside world, the nose
is probably one of the most hospitable: it is warm, very well aerated, moist and supplies unlimited quantities of bacterial
food secreted continuously by the nasal mucosa
contains quantities of glycoprotein
and dissolved salts). In other words it is an ideal breeding ground for bacteria, which are always present.
Many of the common bacteria associated with humans are coloured, Staphylococcus aureus is a golden yellow, for example, and Pseudomonas pyocyanea (to give it its older, but more explicit name) is a shade of blue. Thus the green comes from the mixture of yellow and blue flora!
Normally these and the multitude of other organisms that are inhaled continuously into the nose are flushed out by runny mucus, which is swallowed. The bacteria are usually digested. However, if a situation arises where the flow of mucus slows down and then becomes much thicker in response to an infection of any kind, then the bacteria, in their ideal home, can multiply and produce the coloured mucus described.
Source - The NewScientist