It depends on how long ago the town was settled.
Basically, once a few houses went up, someone would get the idea of building a church. Sometimes, the church was also the schoolhouse. They'd generally build it on the edge of town, and often, but not always, there was a graveyard behind the church. Sometimes, the church grounds were too rocky for burial, and sometimes, the fact that it was also a school figured into the decision. In that case, the cemetery might be a good walk outside of town.
The thing is, the edge of town doesn't stay the edge for long in a growing community. So, while the church and cemetery might have started out on the edge of town in, say 1840, but 1880, it will be surrounded by other buildings.