Pergolas are of two types, free standing and attached to the house. The first type is relatively costlier than than the second, which needs only to be built on three sides with the fourth side being the support of the wall on the house.
The location of the pergola depends upon the purpose for which the pergola is being built. If it is for aesthetic purpose, it can be built in the prime place of the garden as the focal point of attention. If it is built as an extension of the house to give more space and seat more guests, then it can be built adjacent to t he house with the support of the wall of the house.