URLs in emails in app behind nginx

I have a “demo server” where I can run versions of stuff we are working on to show off to clients. I already have a Go app and a Laravel app running, so I really need nginx there.

I configured a vhost for a small phoenix project we are currently working on. I wanted to test my set up, so I fired up up phoenix app as I normally locally, in development mode. I made one singe change, in config/config.exs, changing the URL from localhost to the DNS name of my server.


  url: [host: "some.server.com"],

At this point I was only interested in seeing if my nginx configuration was working, so I fired up with mix phx.server as usual (after doing all the other setup of course). Everything seemed to work fine, except one little detail: the URLs in the registration and login emails contain the port number.

Since this is a demo server, I could of course just bypass nginx and just let the URL contain the port number. But suppose I still want to go ahead the way I have done so far (that way I can let the nginx layer worry about TLS instead of trying to figure that out at phoenix level). Is there a simple way to customize the URL to NOT include the port number in outgoing emails?

Am I right to assume this would be an issue with a production build as well? Assuming, I choose to stay behind a proxy, that is.

The urls will only contain the port if the port is not the default port for the scheme. A port of 4000 is neither the default port of http nor https. It’s also not at all the port the server could be accessed from. So you need to tell the url generation which port it’s meant to use, e.g: url: [host: "…", port: 443, scheme: "https"]

2 Likes

Thanks! That worked perfectly. For some reason I thought it was going to cause the server to try to listen to port 443

The url config is just for the url generation. Listening is configured through the http/https keys on the config.

4 Likes