Nitroglycerin works in the heart arteries by opening up those arteries and allowing more blood to flow through. That's how it can be useful to relieve chest pain. As a side effect, though, that same sort of opening up of blood vessels can occur in the head and the brain, and this is what can lead to a headache.