We first show that a continuous function f is nonnegative on a closed set K subset of R(n) if and only if (countably many) moment matrices of some signed measure d nu = f d mu with supp mu = K are all positive semi-definite (if K is compact, mu is an arbitrary finite Borel measure with supp mu = K). In particular, we obtain a convergent explicit hierarchy of semidefinite (outer) approximations with no lifting of the cone of nonnegative polynomials of degree at most d. When used in polynomial optimization on certain simple closed sets K (e.g., the whole space R(n), the positive orthant, a box, a simplex, or the vertices of the hypercube), it provides a nonincreasing sequence of upper bounds which converges to the global minimum by solving a hierarchy of semidefinite programs with only one variable (in fact, a generalized eigenvalue problem). In the compact case, this convergent sequence of upper bounds complements the convergent sequence of lower bounds obtained by solving a hierarchy of semidefinite relaxations as in, e.g., [J. B. Lasserre, SIAM J. Optim., 11 (2001), pp. 796-817].