An approach that many people find productive is to step back from their negative thoughts and just accept them. This awareness, so that you can take a 'helicopter view' of your thinking, is called mindfulness. It allows you to remove yourself from the emotional struggle involved in such thinking and simply let your thoughts go.
A good analogy is the weather – this changes from bright sunshine to dark and stormy, and can have a huge impact on how we feel. But it's wasted energy spent on getting frustrated with it, and impossible to control – the weather will do what it will do, whatever efforts or complaints we make. So, as thoughts enter our minds, like clouds entering a blue sky, we should try to just observe them and let them pass at their own speed. They may be fluffy clouds – positive thoughts – or dark, stormy clouds – worries and stresses – but we should treat them all the same. Let them do what they will do – stay, move on, at their own pace.
So next time you find yourself lying awake with thoughts racing through your mind, try gently pulling back from them, and see if you can observe them without reacting to them.