【问题标题】:inets httpd: server configuration file syntax (proplist_file)inets httpd:服务器配置文件语法(proplist_file)
【发布时间】:2018-03-02 18:09:21
【问题描述】:

当你像这样启动一个httpd服务器时,配置文件的语法是什么:

inets:start(httpd, 
    [{proplist_file, "./server_config.txt"}]
).

httpd docs 说:

{proplist_file, path()}

如果定义了这个属性,Inets 期望找到所有其他的 此文件中定义的属性。

还有:

属性将从配置文件中获取,该配置文件可以 由一个常规的 Erlang 属性列表组成

但是有了这个文件:

server_config.txt:

[
  {port, 0},
  {server_name, "httpd_test"},
  {server_root, "/Users/7stud/erlang_programs/inets_proj"},
  {document_root, "/Users/7stud/erlang_programs/inets_proj/htdocs"},
  {ipfamily, inet6},
  { bind_address, {0,0,0,0,0,0,0,1} }
]

我得到错误:

$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.2  (abort with ^G)

1> inets:start().
ok

2> inets:start(httpd, [{proplist_file, "/Users/7stud/erlang_programs/inets_proj/server_config.txt"}]).
** exception error: no try clause matching {error,{8,erl_parse,["syntax error before: ",[]]}}
     in function  httpd_sup:httpd_config/1 (httpd_sup.erl, line 144)
     in call from httpd_sup:start_child/1 (httpd_sup.erl, line 52)
     in call from inets:call_service/3 (inets.erl, line 461)

接下来,我尝试了 Apache 语法,但也没有用:

server_config.txt:

Port 0
ServerName "httpd_test"
ServerRoot "/Users/7stud/erlang_programs/inets_proj"
DocumentRoot "./htdocs"
Ipfamily inet6
BindAddress {0,0,0,0,0,0,0,1}

3> inets:start(httpd, [{file, "./server_config.txt"}]).         
{error,"httpd_conf: \"/Users/7stud/erlang_programs/inets_proj\" is an invalid ServerRoot"}

4>

好的,通过去掉引号,我在 Apache 样式语法上取得了一些进展:

Port 0
ServerName httpd_test
ServerRoot /Users/7stud/erlang_programs/inets_proj
DocumentRoot ./htdocs
Ipfamily inet6
BindAddress 0:0:0:0:0:0:0:1

现在,我得到了错误:

8> inets:start(httpd, [{file, "./server_config.txt"}]).
{error,"httpd_conf: 0:0:0:0:0:0:0:1 is an invalid address"}

【问题讨论】:

    标签: erlang inets


    【解决方案1】:

    我找到了proplist syntax。一旦我得到了 proplist 语法,我就缩短了路径:

    server_config.txt:

    [
      {port, 0},
      {server_name, "httpd_test"},
      {server_root, "."},
      {document_root, "./htdocs"},
      {ipfamily, inet6},
      { bind_address, {0,0,0,0,0,0,0,1} }
    ].
    

    注意最后的.!语法是如此明显,难怪文档没有给出示例。 :(

    $ erl
    Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
    
    Eshell V8.2  (abort with ^G)
    
    1> inets:start().
    ok
    
    2> {ok, Server} =  inets:start(httpd, [{proplist_file, "./server_config.txt"}]).
    {ok,<0.73.0>}
    
    3> httpd:info(Server).
    [{mime_types,[{"htm","text/html"},{"html","text/html"}]},
     {ipfamily,inet6},
     {server_name,"httpd_test"},
     {bind_address,{0,0,0,0,0,0,0,1}},
     {server_root,"."},
     {port,49400},
     {document_root,"./htdocs"}]
    

    我还在想如何用Apache syntax 指定一个ipv6 绑定地址。也许 ipv6 是在 erlang Apache 语法实现之后出现的?

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 2014-05-07
      • 2017-12-19
      • 2018-08-03
      • 2023-04-07
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      相关资源
      最近更新 更多