EU (Legends) based answer
The journey of Han Solo from Imperial Officer to Rebel Alliance general was a long and interesting one. He did attend the Imperial Academy at Carida, and graduated at the top of his class with the rank of Lieutenant. As told in the Hutt Gambit,
However, his hard-earned military career was short lived. In 5 BBY, he was dispatched to aid Commander Nyklas in duties including slaving and construction work. In this capacity, Han boarded a derelict slaving craft to find that its cargo (Wookiee children) had escaped and that a badly wounded Wookiee was in the pilot's seat. Nyklas ordered Han to skin the helpless Chewbacca, but Han refused and Nyklas swore to punish the Corellian. Shortly afterward, Han and Chewbacca were put to work on the construction of a new wing of the Imperial Hall of Heroes on Coruscant by Wookiee slaves. An enraged Chewbacca turned on Nyklas, who drew his blaster on the Wookiee. Solo refused to let Chewbacca die; he stunned his commanding officer and helped Chewbacca escape, with the assistance of the Rebel Alliance.
Note that the Rebel Alliance here helped him escape, likely making a subtle impression on him. Part of what made him a smuggler was a bounty issued on his head by the Empire (for treason).
Han also had numerous run-ins with the Alliance prior to the events of Episode IV (some of which are detailed in the video game Empire at War.
Senators Mon Mothma and Leia Organa became aware of Solo when he began to lead efforts to free Wookiee slaves from Kashyyyk, as a favor to Chewbacca, who had begun to lose friends and family members to the slaving effort. Solo reluctantly allowed the Alliance to help him in this effort, despite his disdain for political causes, and the Alliance soon became one of his frequent employers.
After being saved from an Imperial fleet over Corellia, Han and Chewie helped plant an EMP charge on a shipment that was delivered to an Imperial facility over Corulag and helped steal Mon Calamari cruiser schematics on Carida. This last mission almost got them killed, and afterward Han swore off involvement with the Alliance and swore to keep his distance from the Galactic Civil War, until he was thrust into the center of galactic politics again after events on Tatooine.
So this was one of the reasons he was clearly uneasy about getting involved in the Alliance during Episode IV. One other reason was that he was double-crossed by the Alliance in another mission, detailed in the novel Rebel Dawn:
Solo's heaviest involvement with the fledgling Rebel Alliance occurred when he and other smugglers, including Lando Calrissian and Jarik Solo aided Bria Tharen's Red Hand Squadron in raiding the Ylesian colonies and putting them out of business—a plan endorsed, aided, and supported by Jabba, a business rival of Ylesia. In the subsequent battle, the Alliance forces were victorious, but several smugglers, including Jarik Solo, were killed. Han and his smuggler friends were double-crossed by Tharen who seized all the spice and treasures that were to be the smugglers' reward for the Alliance.
Soon afterward, he met with Tharen again during a Hutt-sponsored treasure hunt for the Yavin Vassilika. Once again, Tharen took the prize for the Rebellion, while Solo and his smuggling associates were left with nothing. Solo and Tharen left on poor terms on both occasions, since Solo refused to give up his independent ways and join Tharen in the Alliance.
Once the events of Star Wars Episode IV began, Han (reluctantly at first) began to be drawn in by the Rebels (not the smallest factor of which was Princess Leia Organa). His reward for saving the Princess was stolen almost immediately, and although it was retrieved, he gave the money back to the Alliance. Additionally, when he found some treasure, he used much of it to purchase new X-Wing fighters for the Alliance.
As he became closer to the Alliance, he eventually was responsible for the creation of Renegade Squadron, a smuggler-based Rebel espionage unit (appearing in video and card games). By the time of Episode VI, Han was solidly on the side of the Rebels, and when the bounty on his head was lifted by Jabba's death, he was able to devote his time to the cause.
Solo was likely influenced by a former lover, Bria Tharen, who he rescued from slavery. Bria died at the Battle of Toprawa fighting for the Rebellion. Of course, the influence of Leia was a much larger factor.