If you're in occassional discomfort and it's impacting your wellbeing having an aspirin once in a while is probably not a huge deal.
If you have recurring pain constantly or frequently then you need medical attention and you should follow that guidance, not what anybody says on the Internet.
Thank you. People with chronic headaches or migraines are the ones that should not follow this advice, as painkiller-induced headaches are a thing and only make matters worse. Just see a doc.
As for occasional headaches: It's going to be a lot easier fixing the issue that lead to a headache once you don't suffer.