301 redirects to incorrect domain

Make sure you also have X-Forwarded-Proto and X-Forwarded-For.