Stocks rose for a second day on Tuesday on optimism that a solution to Greece's debt crisis was near, although low volume indicated underlying nervousness in the market.

Buyers snapped up shares after the S&P 500's 7 percent swoon since April, mostly in commodities and technology shares, as investors raised their exposure heading into quarter-end and before earnings season in July.

Volatility has remained elevated. The CBOE VIX Index <.VIX>, Wall Street's fear gauge, has only fallen modestly in recent days even as stocks have risen, suggesting investors are cautious. That has kept volume low as well, with 5.91 billion shares traded on the NYSE, AMEX and Nasdaq exchanges, below average.

It shows a level of skittishness. The conviction level is not at screaming highs buying these rallies, said Ciaran O'Kelly, head of equities at Nomura in New York. That would absolutely be a cause for concern.

The Dow Jones industrial average <.DJI> gained 145.13 points, or 1.21 percent, to 12,188.69. The Standard & Poor's 500 Index <.SPX> rose 16.57 points, or 1.29 percent, to 1,296.67. The Nasdaq Composite Index <.IXIC> added 41.03 points, or 1.53 percent, to 2,729.31.

The S&P 500 has now rallied more than 2 percent in the last two days.

The first of two key votes to approve budget-cutting measures in Greece, crucial for receiving international aid, is set for Wednesday.

All eyes will continue to be on the situation in Europe as we go into the second half of the week, said O'Kelly. The world is watching events in Greece unfold over the next 48 hours.

Cyclical areas of the market such as energy, retail and materials, which are more sensitive to shifts in the economy and have underperformed this year, strengthened.

The S&P energy index <.GSPE> surged nearly 2.7 percent, the biggest gainer among S&P sectors. Halliburton Co gained 5.3 percent to $48.69, while Chevron Corp was up 1.5 percent at $100.35.

In an advance indication of earnings season, Nike Inc surged 10.1 percent to $89.90 a day after reporting fourth-quarter earnings that beat expectations, while orders suggested robust strength for the future.

The greater risk to the market is that the news is not negative and we rally on good earnings, said Marc Pado, U.S. market strategist at Cantor Fitzgerald & Co in San Francisco.

The more the market pushes higher, the more it makes the people who are under-exposed nervous, he said.

Greek lawmakers will vote Wednesday and Thursday on measures which must be passed to receive the next payment. If Greece doesn't get the funds, investors fear a Europe-wide crisis and credit market freeze could follow.

Also helping sentiment, progress was reported in talks to persuade European banks and insurers to voluntarily roll over maturing Greek debt.

Although investors were generally optimistic about Greece, the CBOE's Volatility Index suggested some caution. The index stood at 19.23, a number considered relatively high.

While the equity markets have rallied this week, the VIX has held in, losing only about one point so far this week, reflecting the nervousness that persists in the market with the upcoming vote, said derivatives strategists in Nomura in New York.

(Reporting by Edward Krudy; Editing by Kenneth Barry)