I live in a nearby town:
--I live somewhere
--That place is near
I live in a town nearby.
--I live in a town
--I do that nearby
I live in a near by town.
(awkward but I guess grammatical)
--I live near here
--I live not inside, but close to the town (some important town, maybe where we are now, or the big one that is close, etc.)
In the end, the firs two have essentially the same semantics. But the emphasis is a little different. In the first the focus is on the town. In the second, it's on the location that the living (in the town) happens.
The third is a little awkward and means something else.
EDIT: The third sentence is ungrammatical. I misread it when first writing this. "in a near by town" is just not something that we would say in English. That's either mixing two ideas, or just writing a space where there should not be one ("nearby").