We propose a model-based "Military Taylor Rule" - a simple policy rule to determine the optimal level of military spending given foreign threats and war risks. In our model, countries adjust their defense expenditures in response to changing probabilities of war, driven in particular by the military spending of allies and rivals within their geopolitical network. We test the model's predictions using a long-run dataset on military expenditures, alliances, and rivalries for 60 countries over 150 years. Analogous to the Taylor rule in monetary policy, we find that a small set of observables - domestic GDP, and the military spending of allies and rivals - explains most of the cross-country and intertemporal variation in defense spending. To address endogeneity in the military spending of allies and rivals, we exploit exogenous trade windfalls and losses in the network driven by global price shocks. Our results show that governments respond strongly to military buildups by rival countries, but only weakly to reductions in allied spending, consistent with deterrence motives. Higher domestic GDP is associated with greater defense spending, reflecting both stronger fiscal capacity and the larger economic stakes it seeks to defend.