In navigation, red is traditionally associated with the left hand (port) side and green with the right hand (starboard) side of ships. It is obvious, however, that the descriptions right and left are ambiguous and depend upon the direction you are facing. Thus it is necessary to adopt a convention: red is kept to the left on entering port and to the right when leaving port. For navigation at night, this system is applied to both buoys and lighthouses. In harbours, it is common to have two lighthouses at the harbour entrance that use these colours, i.e. a red lighthouse showing a red light at night, and a green lighthouse showing a green light at night. Typical examples of this occur at Calais in France and Aarhus in Denmark.
Having said all that, some lighthouses adopt coloured lights for slightly different purposes. As in road traffic lights, we associate red with stop and danger, and green with go and safety. So, lighthouses can have red and green sectors, i.e. when a ship is in a certain direction from a lighthouse it is in a danger zone and sees a red light from the lighthouse. In other, safer parts of the sea around the lighthouse it sees a green light, or just white. Some lighthouses show only red light, say, or only green light, simply as a distinguishing mark from other lights in the vicinity.
The coloured light is created simply by having a filter of the given colour placed in front of the white light source. A natural follow-on from that is that, because some of the constituent parts of the original white light have been removed, the single colour light has a lesser intensity and therefore its range of visibility is shorter. You will frequently see that, if a lighthouse has a white light with red sectors, the range of the white light will be 15 miles, say, and the red will be 13 miles. Blue is almost never used as a colour for a navigation light, except in some small buoys. Blue is the least efficient colour in just about all respects, being harder to see and most reduced in intensity when extracted from white light.
In coastal and harbour areas, it is sometimes easier to distinguish coloured light at night than it is white light because there are so many other lights around, lights from houses and roads, for example. Thus, a coloured light is more readily distinguished for navigation, especially when it flashes too.