An American soldier stands guard at the Taji base complex, which hosts Iraqi and U.S. troops. (Ali al-Saadi/AFP/Getty Images)

In Iraq’s western Anbar province, more than 300 U.S. troops are posted at a base in the thick of a pitched battle between Iraqi forces, backed by tribal fighters, and well-armed Islamic State militants.

The militants, positioned at a nearby town, have repeatedly hit the base with artillery and rocket fire in recent weeks. Since the middle of December, the U.S.-led military coalition has launched 13 airstrikes around the facility.

U.S. troops have suffered no casualties in the attacks. But the violence has underlined the risks to American personnel as they fan out across Iraq as part of the expanding U.S. mission against the Islamic State, even as President Obama has pledged that U.S. operations “will not involve American combat troops fighting on foreign soil.”

In a sign of the risks, military officials said American soldiers have been transported to the Ayn al-Asad base under the cover of night by helicopter — partly to maintain a low profile for the renewed U.S. operation in Iraq but also to protect U.S. personnel amid fierce fighting west of the capital, Baghdad.

Under Obama’s plan to aid the Iraqi government, the number of U.S. troops in Iraq is expected to grow to about 3,000 from just under 2,000 now. Not only have they been deployed in Baghdad and the northern city of Irbil, but in recent weeks they also have been sent to Anbar and to training sites flanking the capital.

Overall, they are a tiny force compared with the more than 160,000 U.S. troops who were stationed in Iraq at the height of the 2003-2011 war. But American military officials recognize that Iraq remains a “dangerous neighborhood in places,” as a spokesman for the U.S. Central Command put it.

“We are aware of those risks, and we are taking appropriate measures to mitigate them,” said the spokesman, Col. Patrick Ryder.

While U.S. commanders have suggested that U.S. ground activities might expand, troops are limited to advising local commanders and retraining elements of Iraq’s army. The Americans are confined to military headquarters or training bases at four sites.

Those sites include al-Asad in Anbar, a largely Sunni province that has been particularly volatile and provided a foothold for Islamic State forces in Iraq. Militants now control much of the province, including the city of Fallujah and the town of Hit.

If Anbar falls, Baghdad would be at even greater risk, because militants could more easily bring reinforcements and weaponry in from neighboring Syria.

The United States and its allies have sought to counter that threat with airstrikes, recently attacking militant positions around al-Asad and other parts of Anbar.

Suleiman al-Kubbaisi, a spokesman for Anbar’s provincial council, said Iraqi forces are battling to reclaim areas around Baghdadi, a town about 10 miles from al-Asad. In the meantime, he said, militants are using those areas to fire artillery and rockets at the base where Americans are stationed.

Sheik Naim al-Gaoud, an elder of the Albu Nimr tribe in Anbar, said Islamic State militants were dangerously close to the base and to Iraqis who lived nearby. He called for additional airstrikes and American operations to defend Anbar. “There is definitely more activity in this area than there was before,” he said. “If [militants] had the chance, they would attack Ayn al-Asad.”

But Jessica Lewis McFate, an analyst with the Washington-based Institute for the Study of War, said the militants appeared to be focusing their efforts on ensuring that Iraqi forces cannot use the base to block their attempts to capture other, more strategic parts of Anbar.

Al-Asad lies between areas under Islamic State control, and the group will eventually have to link up those areas if it is to conquer the province. Militants are still fighting for Ramadi, another important city. Iraqi forces have so far defended other strategic areas and sites such as the Haditha Dam.

The militants’ goal is “not necessarily to try to overrun the base but to try to pin forces in that fight,” Lewis McFate said.

A U.S. defense official said artillery and rocket attacks on al-Asad had been “very sporadic and ineffective.” U.S. and Iraqi officials said many of the projectiles landed outside the base.

Islamic State fighters are also contesting the area around Taji, a district north of Baghdad where other U.S. military advisers are stationed.

Artillery and rocket attacks are far from unusual in Iraq. They were a daily occurrence for much of the 2003-2011 war, as militants frequently targeted the U.S. Embassy in Baghdad’s Green Zone and military bases across the country.

Gen. Martin E. Dempsey, chairman of the Joint Chiefs of Staff, said in the fall that he expected the Islamic State to launch such attacks on Baghdad.

To minimize the risks, security is being enhanced at the other training sites where U.S. and allied troops will be stationed, the defense official said. Iraqi forces will provide security at the training sites, which include facilities north and south of the capital.

Much of Iraq’s military collapsed in June, when soldiers abandoned their posts as Islamic State forces advanced. Some Iraqi troops fled an Anbar base in the fall during an Islamic State assault there.

Cunningham reported from Baghdad.