Site.domain returns 127.0.0.1 behind Nginx

Fixed an issue where `site.domain` returned 127.0.0.1:port# rather than the base URL in the email subject and template.  This is an issue when running uwsgi/Gunicorn behind a proxy server like Nginx.  Now we allow `site.domain` to be obtained  from the database value first (if it exists) then from the url if it doesn't.