0

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

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

httpd 文档说:

{proplist_file,路径()}

如果定义了这个属性,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"}
4

1 回答 1

0

我想通了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 是在 erlang Apache 语法实现之后出现的?

于 2018-02-26T22:40:15.730 回答