How to get the same vim colors in terminal and tmux

I have just started using tmux. One small problem I ran into was the colors in vim not matching when using vim inside tmux vs running vim from the terminal on Ubuntu. I found the fix on stackoverflow and it is just a matter of adding

set -g default-terminal "screen-256color"

to the ~/.tmux.conf file. And then adding

set background=dark

to the ~/.vimrc file. Weird, but it worked.