Steve's definition is good. But seeing as I wrote the rest of this already, I'll post it anyway.
It's an English thing, JoJo - by which I mean "English English", as opposed to "American English" or "Australian English". I'm not sure where it originally came from, but it refers to the traditional ability of an English gentleman to bear up under pain or pressure and not reveal any weakness. It is pretty much obsolete now, more used in jest or parody than in real life.
When a child is about to cry and is trying hard not to, usually the giveaway is that his upper lip starts to quiver. Shortly after that, he bursts into tears completely. (I suspect that there is a sort of reflex action here - once your lip starts to quiver, it seems to trigger the whole waterworks.)
So, the advice to keep a stiff upper lip, no doubt, began as something that you would say to help a child avoid bursting into tears - especially a boy child, more especially one from the upper classes, and probably just after you discovered him doing something naughty and just before you give him six of the best. (i.e., a beating with a cane.) Indeed, you are probably as concerned that the child take his punishment in a "proper, manly way" and thus earn both his own and your respect, as you are with the misbehaviour that prompted the punishment in the first place.
But it came to be something that would be said between adults. It's easy to imagine, say, one military officer saying it to another just before they do something especially dangerous or difficult (leading a charge, perhaps), or more commonly as helpful, manly advice to a fellow gentleman who has just recieved bad news - perhaps his wife has left him or his child died.
"Well, there is nothing for it, Old Chap, you'll just have to keep a stiff upper lip."
This means, in the classic understated English way, "I sympathise with you, and by reffering to this childish way of not showing your feelings in this light-hearted manner, I am inviting you too to make light of it (as a gentleman should), and I am reinforcing in you our shared value - viz, that it is unimportant what one actually feels, but one must on no account allow one's personal feelings to show on one's face. One may lose one's loved ones, go bankrupt, suffer dreadful physical pain - and these are all things that one would rather not have happen, of course - but the really important thing is keep up appearances. We can't put on a bad show here, by Jove. Honour of the Regiment and all that, what? Care for another pink gin, old chap?"
They are a strange people, the English.In this enigmatic phrase there is a lot to be learned about their obsession with appearances, with never showing emotion - and with doing the right thing no matter what. I don't think it is going too far to say that here we see both the greatness of the British Empire and its central, essential weakness.