QUESTION: The word "nearby", is it an adjective, a preposition, or an adverb?
Consider the following three examples (where the first two are somewhat similar to the OP's examples):
[A nearby house] was for sale.
[A house nearby] was for sale.
A house was [nearby], and it was for sale.
Let's look at the possibility that all three examples are using a preposition "nearby".
Actually, this is the position that I will be supporting in this answer post--that the word "nearby" in the three above examples (and also in your first two examples and in the rest of your examples) are prepositions.
CAVEAT: This is only an argumentation. It does not mean that this argumentation is "correct"; and it doesn't mean that other reasonable argumentations which differ from my position cannot be made.
Argumentation:: "Nearby" is a preposition
First, I'll present some stuff about the semantics of the word "nearby" (as used in all the examples, mine and the OPs), and try to show that the semantics are associated with a relationship that is very similar to those of locative prepositions.
Second, I'll present some syntactic tests to try to show that the word "nearby" as used in examples #1 and #2 is an internal dependent of a noun phrase (NP); and that it is a locative complement in clause structure in example #3.
SEMANTICS:: the relationship of "nearby()"
Many locational prepositions have an associated semantic relationship that takes two arguments. Usually both arguments can be locations, or one is a location and the other is a situation. For instance:
- The tree is near/nearby the river.
In that above example, there is the relationship of "nearby()" that involves the two arguments "the tree" and "the river". That is:
- nearby( the tree, the river ) <-- semantic relationship
This relationship nearby() is associated with the meaning of the words "nearness" and "near" and "nearby", which is the meaning that two things are near each other.
Many times one of the arguments of nearby() can be covert (that is, implied or understood from context). For examples of this:
- A.1. "Go near/nearby the river."
- A.2. nearby( "you":implied, the river )
- B.1. "The tree is near/nearby
- B.2. nearby( the tree, "the river":implied )
- C.1. "The tree is near/nearby
where we are."
- C.2. nearby( the tree, "where we are":implied )
In examples #A-C, one of the arguments is not explicitly expressed in the example sentences.
For an example where one argument can be a situation:
- D.1. "Tom killed a bird near/nearby the river."
- D.2. nearby( Tom killed a bird, the river )
where the first argument is the situation describe by "Tom killed a bird".
(ASIDE: For more info on this sort of topic, please see Araucaria's answer post.)
Now, as for adjectives, in general they have an associated property type of relationship that has just one argument, where that argument is something that can have that property. Often, that something can also function as a predicand. For example:
the [tall] boy
The boy is [tall].
For both, there is the relationship "tall()":
where the "boy" is that something that has the property of "tall" (tallness).
But the relationship nearby() doesn't take just one argument. And so, that is another reason for the unlikelihood of the word "nearby" as being an adjective.
In other words:
Think of the semantic relationship "nearby()" as basically involving two things that are near or nearby to each other. You need two things. For example, if you are near a tree, then two things are near each other: "you" and "the tree". That gives nearby(you, tree). Notice that you can't have nearness ("near" or "nearby") with just one thing, for that wouldn't make any sense at all. (Except when one thing is a thing and the other a situation, as already shown above.)
So this relationship associated with the word "nearby" takes two arguments: nearby(x,y). One thing is near another thing -- that necessarily involves two things, thus two arguments. Though, one of the arguments might not be explicitly mentioned. For example: "the tree is nearby". In this example, one thing is "the tree" and the 2nd thing is understood by context, and so the 2nd thing could be the speaker or some other point of reference.
It is common for many prepositions to be associated with two arguments like this. Think of other prepositions like: on, in, off, out, above, under, etc. The preposition indicates the relationship between two things, e.g. "on" means that one thing is on another thing, "off" means that one thing is off another thing, etc.
Now let's look at the adjective tall(). It takes only one argument. One thing has [the property of] tallness. E.g. "Tom is tall" and "the tall boy", each of them is represented by tall(Tom/the boy) with only one argument. There is no other 2nd thing: neither explicitly given nor implicitly understood. It is common for adjectives to be associated with exactly one argument like this.
Now compare that to "the tree is nearby" and "the nearby tree". Both of them actually have two arguments for nearby() because there are two things involved in this relationship: one thing is "the tree" and the other thing is some understood reference point (the speaker or something), because you need two things for "near" or "nearby" to make sense.
Conclusion: We consider "tall" to be an adjective in both "Tom is tall" and "the tall boy". Part of that reason is that tall() is a relationship that takes one argument. Note that in "Tom is tall", we do not consider "tall" to be an adverb -- it is still an adjective. Correspondingly, for "the tree is nearby" and "the nearby tree", for both of them the word "nearby" has the relationship nearby() which takes two arguments, and so, it seems reasonable to consider both occurrences of the word "nearby" to be prepositions. (And, for similar reasons, it seems reasonable to consider the word "nearby" in "the tree nearby" to also be a preposition.)
SYNTAX:: Some constituency tests:: Clefts
Identifying constituents is often an important, or a necessary, step in making an argumentation. Cleft constructions, such as it-clefts and pseudo-clefts, can often be helpful in identifying constituents. In general, an element of the original clause is foregrounded in the cleft versions; and if that element can be successfully foregrounded, then that is evidence that that element is a constituent.
To support the preposition argument, I will make attempts to show that the expressions within the brackets ("[xx]") in the following three examples are (via tests) constituents:
1.a. [A nearby house] was for sale. <-- original #1
2.a. [A house nearby] was for sale. <-- original #2
3.a. A house was [nearby]. <-- first main clause in the original #3
For #1.a and #2.a, the expressions "a nearby house" and "a house nearby" would be considered to be subject NPs--thus, a constituent--for those two examples respectively. For #3.a, the expression "nearby" would be considered to be a constituent by itself.
The constituent test for #2.a is quite important here, because if it is shown that the expression "a house nearby" is a constituent--an NP--then that could weaken the argument that the word "nearby" within that expression "a house nearby" is an adverb.
[ASIDE: Note that relatively rarely does an adverb function as a post-head dependent of a noun or nominal (though they do exist, e.g. "the people were upset by the arrival recently of a tiger"). Though, an adverb does often function as an external modifier in an NP, e.g. "the car alone", or else as an element that is embedded inside a phrase that is itself a dependent of the NP.]
To show how unlikely it is that the word "nearby" in #2.a could be an adverb, let's add stuff after it:
- [ A house [nearby] [that Tom could afford] ] was for sale.
Notice that the relative clause "that Tom could afford" is an internal dependent of the subject NP that is headed by the noun "house". And that big subject NP is a constituent, as can be seen via a cleft:
- It was [ a house [nearby] [that Tom could afford] ] that was for sale.
and it is structured similar to:
- It was [ a house [near the park] [that Tom could afford] ] that was for sale.
which uses the PP "near the park" instead of the PP "nearby".
[ASIDE: Though, it seems that, in this discussion of these last three examples that were just given, it probably doesn't necessarily rule out the possibility of interpreting the word "nearby" as being an adverb in them.]
Clefts can be used to try to show that the expression "a nearby house" is a constituent in #1.a.
1.a. A nearby house was for sale. <-- original
1.b. It was a nearby house [that was for sale]. <-- it-cleft
1.c. [What was for sale] was a nearby house. <-- pseudo-cleft
1.d. A nearby house was [what was for sale]. <-- reversed pseudo-cleft
Clefts can be used to try to show that the expression "a house nearby" is a constituent in #2.a.
2.a. A house nearby was for sale. <-- original
2.b. It was a house nearby [that was for sale]. <-- it-cleft
2.c. [What was for sale] was a house nearby. <-- pseudo-cleft
2.d. A house nearby was [what was for sale]. <-- reversed pseudo-cleft
In #2.b, the NP "a house nearby" is foregrounded. This shows that the word "nearby" is a post-head dependent within the NP. That is, the word "nearby" is part of that NP.
Let's also try to show this (that the word "nearby" is part of the NP) when the constituent isn't the subject. For instance:
n.a. They bought a house nearby.
n.b. It was a house nearby [that they bought]. <-- it-cleft
n.c. [What they bought] was a house nearby. <-- pseudo-cleft
n.d. A house nearby was [what they bought]. <-- reversed pseudo-cleft
Those above examples, again, show that the word "nearby" is part of the NP constituent "a house nearby".
Let's try to show that the word "nearby" is part of a constituent NP in the OP's #2 example:
- OP.2a. I live in a town nearby. <-- OP's #2 example
OP.2b. It is [in a town nearby] that I live. <-- PP constituent
OP.2c. It is [a town nearby] that I live in. <-- NP constituent
OP.2d. * It is [nearby] that I live in a town. <-- ungrammatical.
What/Where I live is [in a town nearby]. <-- PP constituent
Where I live in is [a town nearby]. <-- NP constituent
OP.2b * What/Where I live in a town is [nearby]. <-- ungrammatical.
ASIDE: Notice that the word "nearby" cannot be replaced by "near" in the OP's #2 example:
- * I live in a town near. <-- ungrammatical
ASIDE: If the word "nearby" was an adjective in the OP's #2 example, then because it is a postpositive modifier (i.e. post-head modifier), it would sometimes have a slightly different meaning when compared to the attributive use of the word "nearby". (Supposedly, according to some linguists.) That is:
This topic is discussed in the textbook SPE, page 392:
a. All navigable rivers are being patrolled.
a'. All rivers navigable are being patrolled.
b. Every available penny was put into their project.
b'. Every penny available was put into their project.
This, however, does not mean that we can simply make our eventual rule for the division of labor between prenominal and postnominal modifiers optional in the case of "simple" A's. As Bolinger (1967a) pointed out, when both word orders are possible (thus, excluding examples as in (3)), they differ in the meanings that they can express: postnominal modifiers can only express "ephemeral" properties, as in (7a'), which refers to those rivers that happen at the moment to allow navigation (thus, perhaps excluding some rivers that normally allow navigation but at present are blocked by ice, and including some rivers that normally do not accommodate ships but happen to be usable at the moment by ships because of an abnormally high water level), (fn 8) while prenominal modifiers can express not only ephemeral but also "permanent" properties, as in (7a), which can refer to the rivers that normally allow navigation.
Accordingly, simple A's that refer to permanent properties are restricted to prenominal positions:
Clefts can be used to try to show that the expression "nearby" is a constituent in #3.a.
3.a. A house was [nearby]. <-- first main clause in the original #3
3.b. It was nearby [that a house was]. <-- it-cleft (ungrammatical?)
What/Where a house was] was nearby. <-- pseudo-cleft (dubious?)
3.d. Nearby was [what a house was]. <-- reversed pseudo-cleft (ungrammatical?)
This section doesn't seem to be of much use in trying to determine the category of the word "nearby".
Prepositions and adverbs and adjectives can often, or sometimes, be foregrounded by an it-cleft:
It's [downstairs] they want to play. <-- preposition
It isn't [often] they're as late as this. <-- adverb
It wasn't [green] I told you to paint it. <-- adjective
The above three examples were borrowed from CGEL pages 1418-9.
Note: The textbook SPE might have some related info as to the difficulty that is seen in this section (w.r.t. example #3) on pages 64-5.
There are prepositions that function as attributive modifier or as postpositive modifier.
For attributive modifiers, there's CGEL page 444:
A few prepositions are also found (as attributive modifiers), as in the [downstairs] toilet.
For post-head modifiers, there's CGEL page 446:
A very great range of PPs can function as post-head modifier. Those in [i ] illustrate the most frequent pattern, with the preposition having an NP as complement. In the last example, with as, the oblique NP is interpreted predicatively: Jill was a journalist. We also find prepositions without complements, generally locative or temporal, as in [ii ]; and in [iii ] the prepositions have clauses as complement.
Also, there is CGEL, page 683:
Most location dependents have the form of a PP. A sample of prepositions (and prepositional idioms) heading such phrases is given in:
The items in [i ] occur without complements in the PP: He lives abroad; Nearby, some children were playing cricket.
The above excerpt shows CGEL's opinion on the preposition "nearby".
But I tend to differ with them on this point: the point is that I also think the preposition "nearby" can also occur with complements. For instance: We checked into a hotel [nearby the station]; He went fishing in the creek [nearby the grocery store].
There is also the supporting evidence of "nearby" as a PP with complement in the online Oxford English Dictionary (OED), 2015, in their entry on "nearby" as a preposition. A related excerpt from that OED is provided elsewhere in this thread via a deleted post and someone else's answer post.
NOTE: The word "nearby" could probably be seen as being a type of compound preposition, where it's seen as being related to a combination of the two prepositions "near" and "by". This is similar to some other prepositions, such as: "onto" with "on" and "to", "into" with "in" and "to", "upon" with "up" and "on".
CGEL: The 2002 CGEL is the 2002 reference grammar by Huddleston and Pullum (et al.), The Cambridge Grammar of the English Language. Some of the related pages are:
- pages 331 , 455 [17-8]
- pages 444-7 [9, 11-5]
- pages 624-6 [20-2]
- pages 683 
- pages 1418-9 [11-7], 1421-2 [22-9]
SPE: This is a textbook by James D. McCawley, The Syntactic Phenomena of English, 2nd edition, paperback 1998. Some of the related pages are:
- pages 392 #7
- pages 64-7 #20-9