Your ringer volume adjusts the volume of the sound coming out of the phone when it's ringing. If the phone is not playing media (i.e. no sound is coming out of it) then the volume buttons on the side adjust the ringer volume.
If you are playing media (music, video, etc) out the internal speakers, then the buttons on the side adjust the volume of that media coming out those speakers.
Finally, when you have headphones plugged in, the iPhone knows this and has a separate volume for headphones. Using the volume buttons will adjust the headphones volume when headphones are plugged in.
The reason why these are separate is because sometimes you want to mute your ringer, but still want to listen to media (or vice versa), and because the headphone and internal speaker volumes are different and need to be adjusted separately.