Elixir cookie store希望conn.secret_key_base至少为64字节,但它';已经

Elixir cookie store希望conn.secret_key_base至少为64字节,但它';已经,elixir,phoenix-framework,Elixir,Phoenix Framework,在制作中,我有以下几点: use Mix.Config config :my_app, MyApp.Endpoint, secret_key_base: System.get_env("MYAPP_SECRET_KEY_BASE") 该值是在/etc/environment中设置的,并且足够长,我是从“mix phoenix.gen.secret”创建的。但是,它仍然会抛出一个错误: ** (exit) an exception was raised: ** (Argum

在制作中,我有以下几点:

use Mix.Config

config :my_app, MyApp.Endpoint,
  secret_key_base: System.get_env("MYAPP_SECRET_KEY_BASE")

该值是在/etc/environment中设置的,并且足够长,我是从“mix phoenix.gen.secret”创建的。但是,它仍然会抛出一个错误:

** (exit) an exception was raised:
        ** (ArgumentError) cookie store expects conn.secret_key_base to be at least 64 bytes
            (plug) lib/plug/session/cookie.ex:159: Plug.Session.COOKIE.validate_secret_key_base/1
            (plug) lib/plug/session/cookie.ex:152: Plug.Session.COOKIE.derive/3
            (plug) lib/plug/session/cookie.ex:103: Plug.Session.COOKIE.put/4
            (plug) lib/plug/session.ex:92: anonymous fn/3 in Plug.Session.before_send/2
            (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
            (plug) lib/plug/conn.ex:961: Plug.Conn.run_before_send/2
            (plug) lib/plug/conn.ex:392: Plug.Conn.send_resp/1
            (my_app) web/controllers/home_controller.ex:1: MyApp.HomeController.action/2

是否可以在编译应用程序之前设置该值

如果在配置内部使用
System.get_env(“…”)
,则在编译时检索此值。如果按以下顺序执行操作,则可能不会使用预期的环境变量值:

  • 设置配置
  • 编译应用程序
  • 设置环境变量
  • 运行应用程序
  • 您可以通过运行
    mix compile--force
    来验证这是否是问题所在

    如果按照以下顺序执行步骤,则将使用正确的环境变量

  • 设置环境变量
  • 设置配置
  • 编译应用程序
  • 运行应用程序

  • 对于初学者,尝试只使用
    IO.inspect应用程序。获取_env(:my_app,MyApp.Endpoint)
    。@mudasobwa,它会打印我的公共文件config@mudasobwa,实际上“秘密密钥库”是旧的,短的。但它在我的项目中已经不存在了,我已经在文件中进行了搜索。我已经重新部署了它。它是从哪里检索的?你用什么来构建/部署应用程序@Jerry?该值是在/etc/environment中设置的,并且足够长,@Jerry我没有质疑该值是否已设置。你是否按照我的建议尝试过强制编译?如果不起作用,也可以尝试
    rm-rf\u build