In a Phoenix application, what is the difference between the :port key of the :http and :url configurations?

757 views Asked by At

I'm currently working in a Phoenix app and had this question when modifying my /config/* files.

Currently the configuration for my Endpoint contains the following:

config :my_app, MyApp.Endpoint,
  http: [port: 8080],
  url: [host: "example.com", port: 80]
...

After reading both documentations for the :http config and the :url config its still not clear to me:

What is each :port config used for and how are they different?

1

There are 1 answers

1
Dogbert On BEST ANSWER

The port in :url is used to generate URLs (like the _url Router helpers) within the application while the port in :http is the TCP port the application will bind the HTTP server to. This is useful because your publicly accessible URLs will most likely be port 80 (default HTTP port) or 443 (default HTTPS port), while your application may run on another port behind a reverse proxy, load balancer, or a caching server (like Nginx, HAProxy, Varnish). If there was only one configuration for both, you wouldn't be able to host more than one application on one port of the server while still generating valid URLs in the _url Router helpers.