启动httpd服务器时,配置文件的语法如下:
inets:start(httpd,
[{proplist_file, "./server_config.txt"}]
).httpd文档说:
{proplist_file路径()} 如果定义了该属性,则Inet希望找到该文件中定义的所有其他属性。
和:
这些属性将从一个配置文件中获取,该配置文件可以由一个普通的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"}发布于 2018-02-26 22:40:15
我算出了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"}]我仍然想知道如何用ipv6指定一个Apache syntax绑定地址。也许ipv6是在erlang语法实现之后出现的?
https://stackoverflow.com/questions/48991314
复制相似问题