Light
Light is a big factor in the circadian rhythm of melatonin production:
Melatonin secretion increases soon after the onset of darkness, peaks in the middle of the night (between 0200 and 0400 h) and gradually falls during the second half of the night. However, the melatonin rhythm can be acutely interrupted by exposure to light[1]
Thus, exposure to bright light should be reduced in the evenings to ensure melatonin production for nighttime.
Melatonin production is wavelength dependent and suppressed by blue light. [2] In one study, people were equipped with googles that excluded short wavelength light, while still being exposed to bright light, which resulted in melatonin production similar to what is produced in dim light. [1]
Nutrition
As for nutrition, melatonin is produced from tryptophan, an essential amino acid. It has been shown that eating tryptophan-rich foods increases melatonin production[4].
but the influence is minor if compared with the power of the light–dark cycle
Foods rich in tryptophan are those rich in protein, because tryptophan is an amino acid:
chocolate, oats, dried dates, milk, yogurt, cottage cheese, red meat, eggs, fish, poultry, sesame, chickpeas, sunflower seeds, pumpkin seeds, spirulina, bananas, and peanuts[5]
Supplements
Melatonin is also available as a supplement, and is used for various conditions to do with sleep (circadian rhythm sleep disorders, delayed sleep phase syndrome, etc)[6] However, for normal sleepers, the effect on both sleep on onset and efficiency appears insignificant in meta-analysis of various studies on the subject[7]
Exercise
Exercise has an effect on melatonin levels. Timing this is important, however; in one study I found (short term, medium number of subjects) exercise in the evenings or at night was more beneficial compared to morning and afternoon[8], in another (short term study, few subjects) this was found for evening, but not for late evening/night exercise [9]
Summary
A combination of tryptophan-rich foods, exposure to bright light throughout the day and dimmed light (or at least avoidance of blue light in the evening), combined with exercise (possibly in the afternoon), probably works best for boosting natural melatonin production.