The server uses the following order when attempting to resolve a $variable:
Variables defined at request time using set-variable in obj.conf
Variables defined by the virtual-server element's variable subelement in server.xml
Variables defined by the server element's variable subelement in server.xml
When you define a $variable at request time, it is stored as a name-value pair in the rq->vars pblock. These variables are given a higher precedence than server.xml variables so that server.xml variables can be overridden at request time.