Hello, Jennifer
All four sentences are correct.
In English, there are two words "nearby", so to speak. There is a "nearby" that is an adjective, and one that is an adverb.
In the first sentences in the pairs you posted, "nearby" is an adjective premodifying a noun, it is part of a noun phrase:
"a (nearby park)"
"a (nearby food centre)"
In the second sentence in each pair, "nearby" is an adverb. It modifies the verb more directly; it is not part of the noun phrase.
"We went (to a park) (nearby)." = We went to a park. We went nearby/The park was nearby.
I hope that makes sense