Wikipedia says, the president is the commander-in-chief, if I understand correctly, he delegates to the secretary of defense, who commands the military.
This certainly sounds like there is nothing the military can (legally) do against the president. They basically have to obey him.
Is there a legal way for the military to disobey? Have there been any precedences of the military going against the president, apart from outright coup?
I will add that an "unlawful" order is one that disobeys the law, hence "unlawful." That is ANY law.
Illegal, immoral, or unethical orders. Are orders you do not have to follow because the are unlawful orders.