带有 http 和 https 的 Webmachine?

发布于 2024-10-20 06:26:56 字数 255 浏览 6 评论 0原文

让 https 与 webmachine 一起使用的推荐方法是什么?

我看到有一个获取 mochiweb 使用 https 和 http。我似乎可以将其翻译为网络机器。特别是如何在一个应用程序中处理 http 和 https 请求。

What is the recommended way of getting https working with webmachine?

I see that there is an example for getting mochiweb working with https and http. I just can seem to translate that to webmachine. In particular how do you handle both http and https requests in one app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

焚却相思 2024-10-27 06:26:56

通过对演示应用程序中的 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} }.

i had some success getting multiple listeners with the following change to mywebdemo_sup.erl in the demo app. i haven't tested it much further than that, but hopefully enough to get you started.

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} }.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文