在不同端口上运行 iex mix phoenix.server 不起作用

问题描述 投票:0回答:2

这看起来像一个错误,但我不确定。 谁能告诉我在不同的端口号上运行 iex 是否有效。它始终使用端口 4000。

PORT=4001 iex -S mix phoenix.server   

Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

[info] Running AppMessenger.Endpoint with Cowboy using http on port 4000
Interactive Elixir (1.2.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 19 May 19:53:40 - info: compiled 5 files into 2 files, copied 3 in 714ms
elixir phoenix-framework
2个回答
7
投票

默认情况下,

config/dev.exs
对于凤凰城的端口有一个硬编码值
4000
。如果您想在
PORT
中使用
dev
环境变量中的值,请在
config/dev.exs
中更改:

http: [port: 4000]

http: [port: {:system, "PORT"}]

0
投票

在现代 Phoenix 安装中,您可以使用 环境变量控制此行为。

config/dev.exs
内变化:

http: [
  ip: {127, 0, 0, 1}, 
  port: 4000
]

http: [
  ip: {127, 0, 0, 1}, 
  port: String.to_integer(System.get_env("PORT") || "4000")]
]

使用 direnv 和 Phoenix 项目根目录下的

.envrc
文件来设置端口:

export PORT=4001

© www.soinside.com 2019 - 2024. All rights reserved.