How does medication know where exactly the pain in my body is?

When you miss a step and fall, resulting in excruciating pain in your knee… you take a painkiller. When you accidentally cut your finger while making dinner… you take a painkiller. When you have an inexplicable headache… you take a painkiller. How do these pain killers seem to work in all of these areas of…