Testing the El Capitan installer which has a published URL it will appear in the App Store, but if requested to download no longer says 'not valid for this Mac' it now says 'The requested version of macOS is not available'. Sierra, High Sierra & Mojave are available via direct links - see below. It would appear that in the new Mojave App Store, older purchased OS Installers no longer appear at all, so the 'simple method' of grabbing it from your purchase history is no longer valid. Some users seem to have managed to miss out El Capitan, but High Sierra still seems necessary. This will prepare your machine for the long jump.
If you are trying to jump a long way - say from 10.8 to 10.14 or later, received wisdom is to first upgrade to El Capitan 10.11, then High Sierra 10.13. One thing that still applies throughout is - you need a Mac to get macOS easily & legitimately.
It might be simpler to first check Apple's own page on How to get old versions of macOS (which didn't exist until relatively recently), & come back here if you still have issues. Some of this answer is getting a little dated now, as it's been periodically updated over several years.