I read that the Nazis supported the nationalists during the civil war , what was the thinking? And why wasn't Spain able to join the war on the axis side?
The Third Reich's support for Franco and the Nationalists was a mixture of economic opportunism and geostrategic anxieties. Hitler had received reports from the German embassy that without German aid, the Nationalists would lose the civil war. Hitler feared that with a communist-led Spain at their back, the French would either fall to Bolshevism or have no choice but to accept a Franco-Soviet alliance. When Ribbentrop objected to military intervention, Hitler argued:
If Spain really goes communist, France in her present situation will also be bolshevized in due course, and then Germany is finished. Wedged between the powerful Soviet bloc in the east and a strong communist Franco-Spanish bloc in the West, we could do hardly anything if Moscow chose to attack us.
The influx of German military aid and the Condor Legion would, in Hitler's formulations, prevent this possibility. Hitler was also influenced by the German businessman and head of an export firm in Spanish Morocco, Johannes Bernhardt, who argued that Spanish natural resources would be highly advantageous for the Third Reich's rearmament program and the newly announced Four-Year Plan. The Nationalists quickly worked out an exchange system of raw materials for weaponry. The combat experience of the Condor Legion and the propaganda value gained from leading an attack on the alleged forces of global Bolshevism were also inducements for Hitler to intervene in Spain.
German investments in Spain proved to be a mixed blessing. Although the Condor Legion did gain valuable combat experience, excesses like Guernica increased Germany's diplomatic isolation. European public opinion, especially in Western Europe, began to (correctly) perceive Germany as a rogue state that was not a viable partner. Although the public opinion was largely reluctant to engage in war, the thought of a peaceful coexistence with the Third Reich became increasingly unpalatable. The Soviets intervention on behalf of the Republicans garnered it degree of international prestige among intellectuals and radicals as a leading force in the fight against fascism, even though Stalin would later squander a lot of this goodwill when he signed the Molotov-Ribbentrop Pact.
Germany approached Spain during the Second World War at first as a potential partner. Franco's ideological preoccupation with anti-communism precluded any move away from Spain's neutrality. The Spanish government looked askance at the Molotov-Ribbentrop pact and did not want to engage in a war that would see the Nationalists in an alliance with the USSR, even if an ally by proxy. The unwillingness of Hitler to treat his alliance partners on anything close to equitable levels also meant that the Germans would not offer any concrete assurances of territory or independent action. This meant that negotiations with Spain when Germany had the most to offer her, the time period of the fall of France through mid-1941, were plagued by these two stumbling blocks.
German strategy with regard to Spain shifted after Barbarossa. From here on, the Germans mainly wanted three things from Spain: volunteer soldiers, workers, and raw materials. For the latter, Spain's role in the Second World War increasingly began to echo the role played by the Netherlands during the First World War: a "window" to escape Allied blockade. Spanish exports of tungsten became an essential component of the German war effort as tungsten was an essential mineral for both high-end machine tools and anti-tank ammunition. Franco took advantage of this shortages to restore Spain's gold reserves and pay off some of its debt to Germany and Italy. The Allies also competed with Germans to buy up Spain's tungsten reserves and used other inducements such as an embargo on oil to pressure Spain to break its economic ties with the Axis. Despite this competition, Franco's focus on autarky meant the Spanish economy barely grew during the war and the wartime economy meant shortages and suffering for the Spanish people.
Sources
Bowen, Wayne H. Spain During World War II. Columbia: University of Missouri Press, 2006.
Kershaw, Ian. Hitler, 1936-45: Nemesis. New York: W.W. Norton, 2000.
I can answer to the second part: Franco didn't want to join the war until Great Britain was utterly defeated, since he feared their naval power. He met with Hitler in Hendaya and, after purposefully arriving late, he made demands (supplies, weapons, Gibraltar, French Morocco...) that he knew Hitler would refuse.
On the other hand, Hitler wasn't particularly thrilled about giving into Franco's demands since they would alienate the Vichy government, which instilled him much more confidence in terms of power.
As for the first part, I can only state that Spain is strategically situated to control the Mediterranean through Gibraltar and fare war on Africa. The Canary Islands also provide a safe port for Atlantic subs to resupply.
I'm on mobile right now, but I can expand on this later. Sources include Paul Preston's biography of Franco.
Edited with more data.