Enthusiasm for sunlight as medicine waned after antibiotics began to be widely used during the 1930s, but it has recently revived, as evidence mounts for the complex role that vitamin D — sometimes called the sunshine vitamin, because the skin creates it when exposed to sunlight — plays in human biology.

Over half of Americans do not produce enough vitamin D, a result of spending some 90 percent of our time indoors, according to Dr. Michael Holick, a professor of medicine at Boston University. And that’s a problem, he says, because too little vitamin D can weaken our body’s ability to fight off infections.

While the mechanisms of its action are still not fully understood, a study published last year by Dr. Holick and colleagues reported that vitamin D boosts the expression of hundreds of genes that are thought to help regulate immune function.

Dr. Holick recommends to many of his patients that they take supplements of vitamin D. Overweight people, he says, may need extra high doses. But consult your doctor before doing so, since high doses can cause kidney problems and other complications.

Dr. JoAnn Manson, the chief of preventive medicine at Brigham and Women’s Hospital in Boston and a Harvard professor, says that the jury is still out on optimal levels of vitamin D, though some people might benefit from supplements “to hedge their bets.”

“The best approach is to have a heart-healthy diet and get the nutrients from foods,” Dr. Manson said, and to spend time outdoors in the fresh air and sunlight. “Being physically active outdoors helps people to maintain proper weight, reduces the risk of diabetes and heart disease, benefits bone health, lowers stress and improves emotional well-being. The list of benefits from physical activity is extensive.” Moreover, sun exposure enables the skin to create nitric oxide, which lowers blood pressure and improves cardiovascular health, Dr. Manson said.

But the fact that a little sunlight is good for health does not mean that a lot is better. “Too much exposure suppresses the ability of the human immune system to efficiently detect and attack malignant cells,” which can increase the risk of skin cancer, Dr. Maglio cautioned.