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

1

6

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?

Soraya answered 16/12, 2016 at 20:50 Comment(0)
C
8

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.

Checkrow answered 16/12, 2016 at 20:59 Comment(1)
Thanks for the answer! I think you meant while the port in :http is the TCP port ... though.Soraya

© 2022 - 2024 — McMap. All rights reserved.