Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 654
Daniel Zendejas Avatar asked Dec 16 '16 20:12

Daniel Zendejas


1 Answers

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.

like image 149
Dogbert Avatar answered Sep 23 '22 16:09

Dogbert