HOW you do it is a matter of your own style, and that includes approaching it from different ways based on how the solo section and feel of the song as a whole lead you.
For me, if the song has a simpler part under the solo, I’ll usually loop the part and improv over it repeatedly until I find bits that I really like and gravitate to. They form the foundation, and then I fill in the “white space” the more I go.
If it’s a bit more complicated, or if there’s already a strong melody in the song to work from, I may start with permutations on that melody, finding the dominant notes of it (to my ear) and writing down or improv’ing there.
Other times, I may look at all the chords in the part, find a mode in the right key that contains all of them, and try to write or improv something around that. I don’t “know” the modes and stuff cold, so that’s actual research type stuff, then getting the patterns under my fingers.
One or a combination of those approaches usually yields something I’m satisfied with, at least for the moment.