Why did the Boxer Rebellion break out in 1899?

One of the grounds was the previous humiliation of The Treaty of Nanjing. It was signed on a British Gunboat. The most important terms was that Hong Kong was ceded to the British, 5 Ports were opened to residence and trade, including Canton and Shanghai, foreigners living in the ports exempt from Chinese law,  while import tariffs were reduced to 5% maximum. Although this was not too effective at encouraging Chinese to buy British goods, it still caused extreme humiliation to the Chinese Government and the loss led to a national pride loss for the Chinese people.

Another reason was the humiliating resulting from the treaty of Tianjin. In this treaty, more ports opened to residences to China and foreigners, such as traders and Christian missionaries were given free movement anywhere in the country. Christian missionaries violated China as they had practiced their own religion of Confucianism for 2,000 years, by pressuring local officials to side with Christian converts. All this added up to China's anger at the violation of Chinese traditions, importantly, British and French troops had burnt down the historic, imperial Summer Palace to the ground.

After the British realised Opium was popular in China, they began to trade opium to China. China began to import more of the drug than the products there were being exported from China to foreign countries, causing a trade loss. This created anger and resentment in China, especially since by 1899 they were facing an economic disaster and severe drought.

Furthermore, the Boxer Rebellion was fuelled by the Sino-Japanese War of 1895. This caused anger towards Japan who took away China's tributary state of Korea, which resulted in an economic loss and a further loss of national pride. As Japan increasingly sent missionaries and ambassadors to Beijing, a group of Boxers travelled down the country, killing thousands of foreign missionaries, and invaded Beijing.