简体   繁体   中英

inets httpd: server configuration file syntax (proplist_file)

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

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

The httpd docs say:

{proplist_file, path()}

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

And:

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

But with this file:

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

I get the error:

$ 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)

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

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>

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

Now, I get the error:

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

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

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM