You must know that proteins have shapes, and those shapes are how you can tell one protein from another. Your cells are covered with protein, viruses have protein capsules, it's all protein on the molecular level.Flu Redux (Making Light, thanks Teresa Nielsen Hayden!)
Your immune system (when it's working right) recognizes self and non-self. It protects the self and attacks the non-self. It does this in a couple of ways. First, you have generalized reaction. When cells are distressed, they release cytokines, and those switch on a kind of white cell called the NK-cell. NK stands for Natural Killer (no, I'm not making this up). The NK cells find anything they don't recognize, and, using specialized proteins, destroy it. When you've got an infection, those are the first things that come on line.
The next thing to arrive are the antibodies. These are specialized cells that are keyed to find one specific protein--the foreign invader protein--and destroy it. Before your body can produce antibodies, it has to have been exposed to the antigens (which is what you call non-self proteins), and be sensitized.
Meanwhile, your body is releasing enzymes that act as chemical messengers to produce various effects. Fevers, swelling, sweating, headache ... all enzymes. The aching in your bones that you feel is the marrow pumping out white cells to fight the infection.
Once your body has successfully fought off an invader, the antibodies remain. If they ever again encounter proteins of the same shape, they'll be on 'em fast. The infection won't have a chance to start.