They can be anywhere, subject to the limit of 4 per sector. Note that resource mining starbases don't count towards that total.
But if a planet is within the starbase (SB) Area of Influence (AOI) then any ships in orbit about the planet will receive the SB bonus which is a benefit if that planet is attacked but the planet receives no direct benefit from the SB.
The question is more what you're trying to accomplish with the SB. I knew someone that essentially used military SB's as a "fence" around his area with fleets of 1/1 fighters that became dreadnoughts in the shadow of his fully populated military SB's but that took a long time to setup and was simply that person's preferred style of play.
Often starbases but particularly resource mining SB's are favorite targets of the AI so I could see putting one off to the side to draw away the enemy to their death by the SB enhanced ships underneath.
So I guess the best answer is that it depends on what you're trying to accomplish.