The best way to overcome this problem is really getting in touch with something within you. Feel the beat, the rhythm, everything in the music, get in the "zone." You really have to absorb yourself into the performance and not let other thoughts distract you. Whenever you do these kind of things don't just give a fraction of yourself, give it your 100%. Any moment you lose confidence or lose focus, it shows it every single time in your recording. Don't even think "okay I'm gonna try to be confident." Just bring it man like you've been doing this all the time and you're the dude. It's a psychological thing in your performance why you're not getting the results you want. You gotta really turn that switch on in your mind. It's that drive that'll give you the best results out from you. Don't let any second thoughts hinder your performance and get nervous again. I've heard dudes rap record or freestyle in person and I can tell when they're nervous cuz I can see it physically and it shows in their voice too. On the other hand, I've seen dudes that just go for it not giving a crap and they just get into their zone and its sick. Don't even think that you gotta "try," just bring that shit out of you.
You ever see musicians like pianists and violinists perform? They step on to the stage all normal like everybody else and once they start their performance boom they just get into it. No hesitation ever holding them back. You gotta put your all into it and immerse yourself. Learn to shut everything out of your mind. Don't get into that feeling where you feel like your watching yourself and you feel awkward and lose it. It's just you and your music. It's not even about confidence anymore, it's just you doing your thing and confidence isn't a problem. Once you develop the momentum, you have fun with it and it becomes natural. This is key to do any type of performance like singing, dance, playing whatever instruments, etc. The more you engage yourself without any distractions, the more you'll get out of your voice. Don't lose that energy, but also as you do it learn to control and maintain it.