Nasdaq rallies while S&P 500 heads for biggest August since 1984