This is nothing to do with you.
You've done nothing wrong.
You'll have to tell him to stop ranting at you.
Why should you be his emotional punch bag?
Of course it affects your mental health.
You are enabling the dynamic by just absorbing it.
He's the complainer and you are the sponge who absorbs his 'noise'.
You'll have to stop kneeling and adoring at the altar of his bad mood.
Tell him " you sound angry and you are raising your voice. I've had a tough day and I'd like some peace. Can we talk about this later'".
'Have you thought of talking to the GP about why you are so angry all the time?"
Stop engaging in the content of what he is saying and instead talk about his tone of voice, his body language and the impact of the rants on you.
No matter what job he'll be in this'll happen.
It's him, but he's incapable of self reflection so he assumes it's everyone else's fault.
My DH was like this until I called a halt to it.
I could have been stood naked in the kitchen wearing an orange clown wig and he'd just have come in sighing and moaning about the job again and how terrible everyone else is but not him. Literally not seeing me.
Just an angry monologue.
And that's not relating. It's not a conversation.
He's on antidepressants now and goes to therapy and he's much more self aware.