Your question is very complex and has filled the contents of numerous books.
The distinguished founder of the subreddit, /u/Artrw, has expertise in this topic and wrote about the Act and the Open Door Policy and the Act's religious justification, as well as How did the first Chinese immigrants get to North America? broadly
These answers have further reading if you're interested. See also, for example, Strangers in The Land: Patterns of American Nativism by John Higham, which is on the subredddit's booklist.
/u/keylian previously answered Why were the majority of immigrants to the new world in the late 1800s and the early 1900s primarily from Europe, and not places like China...?
/u/Verbenablu discussed the legal justification for the Chinese Exclusion Act.