While the pair Lagos, Portugal and Saigon/Ho Chi Minh City, Vietnam might be the right one, it looks like above suggested route is a diversion. Originally I hoped to find a shorter route in the far south but this didn't work out, but following the silk route one should be able to find a shorter route.
Unfortunately it is hard to give an optimal answer. It might be doable to find the fastest connection between these two cities (if you know which cities you will pass definitely), but it is harder to find the shortest such route in terms of distance.
I'll here give an outline of the fastest journey along the silk road. This however is far from the shortest such route. Just note that it would be much shorter to go from France to Switzerland, Austria, Hungary and via Ukraine to Russia without going up to Moscow (but going via Voronezh to Samara).
It should be clear that in Europe this is not short but fast. The main difference to above answer is going from Moscow to Astana and onwards to Urumqi and Nanning (via, for example Chongqing).
The trip lengths are (I just state them for the most important changes to the other answer):
- Moscow-Astana: ~57 hours
- Astana-Urumqi: ~42 hours
- Urumqi-Chongqing: ~44 hours
- Chongqing-Nanning: ~22 hours
- Nanning-Hanoi: ~11 hours
Comparing just the time spent on trains (without times needed to change; I think a few of the trains involved in my answer don't run daily, so figuring out this would add some more difficulty), with nsn's answer it takes around 190 hours (not counting the subway ride in Beijing) to get from Moscow to Hanoi. Using my answer, one spends around 177 hours on trains from Moscow to Hanoi. I'm pretty sure though it will take more time to take this route since there are more changes involved.
Unfortunately I don't know of any way to calculate the distance of this route, but I'm quite certain it is shorter.