ollran

ollran

Phoenix uses wrong port

Hi,

I created a new Phoenix umbrella application. I am trying to configure it to use different port, but the port does not change.

$ mix phx.new test --umbrella --no-ecto

In test_umbrella/config/prod.exs:

I uncommented this line:

config :test_web, TestWeb.Endpoint, server: true

and configured the ip and the port:

config :test_web, TestWeb.Endpoint,
  url: [ip: [0,0,0,0], port: 1234],
  cache_static_manifest: "priv/static/cache_manifest.json"

Then I ran:

$ cd test_umbrella/
$ SECRET_KEY_BASE=$(mix phx.gen.secret) MIX_ENV=prod mix phx.server

The server starts, but cowboy listens on port 4000 instead of 1234.

08:14:34.496 [info] Running TestWeb.Endpoint with cowboy 2.6.3 at :::4000 (http)
08:14:34.498 [info] Access TestWeb.Endpoint at http://localhost:1234
08:15:13.928 request_id=Fa1_NZgFyPdDboEAACYH [info] GET /
08:15:13.929 request_id=Fa1_NZgFyPdDboEAACYH [info] Sent 200 in 1ms

$ curl 0.0.0.0:1234
curl: (7) Failed to connect to 0.0.0.0 port 1234: Connection refused
$ curl 127.0.0.1:1234
curl: (7) Failed to connect to 127.0.0.1 port 1234: Connection refused
$ curl 0.0.0.0:4000
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"/>
[...]

Some additional information:

$ elixir --version
Erlang/OTP 22 [erts-10.4.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]
Elixir 1.9.0 (compiled with Erlang/OTP 22)

$ mix phx.new --version
Phoenix v1.4.8

$ uname -a
Darwin MBPro.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu- 
4903.261.4~2/RELEASE_X86_64 x86_64

Marked As Solved

ollran

ollran

Ah yes. I have to use the PORT environment variable:

$ PORT=1234 SECRET_KEY_BASE=$(mix phx.gen.secret) MIX_ENV=prod mix phx.server

Is this a bug? What happens if I use different port in the configuration file?

Also Liked

LostKobrakai

LostKobrakai

In short: The :http config is for listening part, while the :url config is for the url/link generation.

ollran

ollran

Thanks! I found this in test_umbrella/config/prod.secret.exs.

config :test_web, TestWeb.Endpoint,
  http: [:inet6, port: String.to_integer(System.get_env("PORT") || "4000")],
  secret_key_base: secret_key_base

Changing the port here works. I think I will configure my application to use the environment variable everywhere.

NobbZ

NobbZ

Just changing prod.exs might not necessarily help. Especially in an umbrella project you need to be very sure about when to edit which file.

This though is dependant on you overall config structure.

Just open your umbrellas root config/config.exs and try to play through the load_config calls and see if you end up in your applications config/prod.exs.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35953 110
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement