使用http和https的Webmachine?

时间:2011-03-06 08:15:14

标签: https erlang mochiweb webmachine

建议使用https处理webmachine的方法是什么?

我看到有一个获得mochiweb working with https and http的例子。我似乎可以将其转换为webmachine。特别是如何在一个应用程序中处理http和https请求。

1 个答案:

答案 0 :(得分:7)

我在演示应用程序中通过对mywebdemo_sup.erl的以下更改获得了多个侦听器,这取得了一些成功。我没有进一步测试它,但希望足以让你开始。

init([]) ->
    Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
    {ok, Dispatch} = file:consult(filename:join(
                    [filename:dirname(code:which(?MODULE)),
                     "..", "priv", "dispatch.conf"])),
    WebConfig = [
         {name, one},
         {ip, Ip},
         {port, 8000},
         {log_dir, "priv/log"},
         {dispatch, Dispatch}],
    Web = {one,
       {webmachine_mochiweb, start, [WebConfig]},
       permanent, 5000, worker, dynamic},
    WebSSLConfig = [
            {name, two},
            {ip, Ip},
            {port, 8443},
            {ssl, true},
            {ssl_opts, [{certfile, "/tmp/api_server.crt"},
                {cacertfile,"tmp/api_server.ca.crt"},
                {keyfile, "/tmp/api_server.key"}]},
            {log_dir, "priv/log"},
            {dispatch, Dispatch}],
    WebSSL = {two,
          {webmachine_mochiweb, start, [WebSSLConfig]},
          permanent, 5000, worker, dynamic},
    Processes = [Web, WebSSL],
    {ok, { {one_for_one, 10, 10}, Processes} }.