inets httpd:服务器配置文件语法(proplist_file) [英] inets httpd: server configuration file syntax (proplist_file)

查看:127
本文介绍了inets httpd:服务器配置文件语法(proplist_file)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the syntax for the configuration file when you start an httpd server like this:

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

httpd文档说:

{proplist_file,path()}

{proplist_file, path()}

如果定义了此属性,则Inets希望找到所有其他属性 该文件中定义的属性.

If this property is defined, Inets expects to find all other properties defined in this file.

并且:

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

the properties are to be fetched from a configuration file that can consist of a regular Erlang property list

但是使用此文件:

server_config.txt:

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语法,但也不起作用:

Next, I tried the Apache syntax, and that didn't work either:

server_config.txt:

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样式语法上取得了一些进展:


Okay, I made some progress on the Apache style syntax by getting rid of the quotes:

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"}

推荐答案

我想出了proplist syntax.一旦获得了proplist语法,我便缩短了路径:

I figured out the proplist syntax. I shortened up the paths once I got the proplist syntax to work:

server_config.txt:

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} }
].

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

Notice the . at the end! The syntax is so obvious no wonder the docs don't give an example. :(

$ 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语法之后出现的?

I'm still wondering how to specify an ipv6 bind address with the Apache syntax. Maybe ipv6 came after the erlang Apache syntax was implemented?

这篇关于inets httpd:服务器配置文件语法(proplist_file)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆