WENZHOU, China — More than 500 miles from the epicenter of the coronavirus outbreak, 30 million people are in lockdown — some quite literally locked in their homes — as Chinese authorities resort to extreme lengths to curb the spread of a respiratory illness that has stubbornly defied containment.

Across the coastal province of Zhejiang, the worst-hit area after Hubei province, four big cities have essentially put their populations under a form of house arrest: Only one person from each household is allowed to leave, and only every second day, to buy supplies.

To leave their residential compounds and to enter supermarkets, residents must have their government-issued ticket — a kind of passport to the outside world — stamped or their special identification codes scanned. Their temperatures are recorded at every gate.

“Every home has shut its doors,” said Chen Zongyao, a 55-year-old man in northern Wenzhou who, fortuitously, had stocked up on rice and fish before the outbreak reached Zhejiang. “We are totally isolated.”

The world’s attention has been focused in recent weeks on Hubei province and its capital, Wuhan, the root of a coronavirus outbreak that has killed more than 720 people in China and infected more than 34,000. Chinese ­authorities have launched a ­military-style effort to contain the virus in Hubei, building new hospital wards and fashioning huge isolation centers in gyms and stadiums.

But a similar situation is unfolding in Zhejiang, one of China’s most prosperous regions. Alibaba, the megalithic e-commerce company, is headquartered in the provincial capital, Hangzhou, and Xi Jinping, China’s current president, ran the province as party secretary here from 2002 until 2007.

Zhejiang has the most coronavirus infections after Hubei, leading to draconian restrictions in the main cities, from Hangzhou and Ningbo, one the world’s biggest ports, in the north to Taizhou and Wenzhou in the south.

The most severe are in Wenzhou, which has 421 confirmed cases of infection, the highest of any city outside Hubei province. More than 100,000 people from Wenzhou live in Wuhan, and many of them came home for the Lunar New Year holiday, bringing the infection with them.

Public transportation in Wenzhou has been shuttered since Jan. 31, and businesses were ordered to close until at least Feb. 18. Funerals and weddings have been banned.

“I’m telling you, this place is just like Wuhan now. It’s the second Wuhan,” said a woman who works at a rest stop by the southern toll gate into the city, gesturing toward Wenzhou on the other side. She asked that her name not be used.

The tollgate was closed except for two lanes, where police in full protective gear were checking paperwork and temperatures. Only registered city residents were allowed in — and they were told they would not be allowed back out.

“For your health, please be cooperative during the checkup,” a sign said. The cars contained families with babies, grumpy business executives, young couples, all wearing masks.

They joined the line with trucks laden with sweet potatoes and bearing banners on their hoods declaring they were bringing in food supplies. Authorities are sending food — fruit, porridge, bread, instant noodles — to trapped citizens every day.

There has been talk in town about food shortages. At a Walmart in Wenzhou, there were long lines of people — sometimes stretching for more than two hours — waiting to buy rice, instant noodles and canned foods. The store was completely out of fresh food, one shopper said.

As the outbreak took hold, about 20,000 people were placed under “centralized quarantine” in Wenzhou hotels, where they are now joined by anyone who has had contact with an infected person or has been to Hubei in the previous two weeks.

Chen Bin, a lawyer, was sent to centralized quarantine after returning from his hometown in Hubei, along with his two children and his in-laws.

Now, they are all in different rooms in the same hotel and can communicate only through their phones. At the beginning, Chen said, he couldn’t sleep because he was worried that “even the air is filled with germs.”

“I’m going crazy,” a quarantined woman wrote on Douyin, as TikTok is called in China, from a Wenzhou hotel room. “Not comfortable with sleeping, not comfortable sitting. My whole body is aching,” she wrote, taking selfies.

Others are even less happy.

When police with SWAT-style gear including plastic shields showed up at the home of one Wenzhou woman who had close contact with a confirmed case, she refused to go into centralized quarantine.

“I don’t need it!” the woman, in pink pajamas, yelled at the police.

“It’s a must! It’s a government order!” the officer yelled back, a video of the encounter shows.

The woman stabbed at them with a knife to try to fend them off. They eventually subdued her and got her into quarantine.

But she is an unusual case. There has been relatively little grumbling here: Wenzhou people can see all too clearly, thanks to the example of Wuhan, what happens when movement is allowed.

“I think people understand and agree with the policy of shutting everything down,” Chen said. “They are scared of the virus.”

In an apartment complex nearby, a 32-year-old mother who uses “Lemon” as her English name said she had learned to cook during the lockdown, which she is spending in her apartment with her husband and 4-year-old daughter.

“I’m fine with staying at home, even for longer,” Lemon, who works in a government-related job and also did not want to be identified, said over the phone as her daughter giggled nearby. “She’s too small to understand what’s happening. She just knows that ‘the virus that wears a crown’ is terrible and we can’t leave home.”

A woman who runs a small hardware factory in the area was matter-of-fact about having to close her business for an unspecified period. “Life is more important than making money,” said the woman, who wanted to be identified only by her surname of Xia.

Still, the situation in the city has led to an outbreak of anti-Wenzhou sentiment similar to the ostracism people from Hubei have described. People who were ordered to quarantine themselves at home found they were unwelcome in their compounds, with their neighbors directing them to a hotel instead.

Some people in other parts of Zhejiang reported extreme responses when they returned from trips to Wenzhou.

Local authorities put a “No visitors allowed” sign on Allen Li’s family home in Hangzhou and locked the door with a metal chain from the outside. “We argued with them, but they said it’s a decision from above,” Li told the South China Morning Post. “We understand we should not go out. But this is not humane. What if there’s a fire at our home at midnight and we can’t get anyone to unlock it?”

For now, people are hunkering down. Chen, the well-stocked resident from northern Wenzhou, expects to be at home for weeks: “I think there’s no hope for the lockdown finishing this month.”

Gerry Shih in Hangzhou and Wang Yuan in Wenzhou contributed to this report.