zoukankan      html  css  js  c++  java
  • 启动erlang/OTP里面的Web服务器

    erlang OTP是一个完整可靠的大型库,乃前人艰苦卓绝之成就;现在尝试一下里面的application inets的Web服务器httpd,写一段代码调用inets服务:

    1 -module(inets_httpd).
    2 -export([start/0]).
    3 
    4 start() ->
    5     inets:start(),
    6     inets:start(httpd, [{bind_address, {192,168,178,130}}, {ipfamily, inet}, {port, 18080}, {service_admin, "XXXXXXX@163.com"}, {server_name, "whyang.yang.net"}, {server_root, "."}, {server_tokens, full}, {document_root, "./html"}, {directory_index,["main.html", "index.html"]},  {log_format, common}, {error_log, "/var/inets_httpd_error_temp.log"}, {security_log, "/var/inets_httpd_security_temp.log"}, {transfer_log, "/var/inets_httpd_transfer_temp.log"}]).

    编译:

    [root@whyang ~]# erlc inets_httpd.erl
    [root@whyang ~]# l -tr
    -rw-r--r--   1 root root      832 Jul  8 19:01 inets_httpd.beam
    [root@whyang ~]#

    执行方式1:

    [root@james ~]# erl -noshell -s inets_httpd start

    执行方式2:

    [root@whyang ~]# erl
    Erlang/OTP 17 [erts-6.4] [source] [64-bit] [async-threads:10] [hipe] [kernel-poll:false]
    
    Eshell V6.4  (abort with ^G)
    1> c(inets_httpd).
    {ok,inets_httpd}
    2> inets_httpd:start().
    {ok,<0.50.0>}
    3>

    浏览器看看,服务器是什么(居然还是用Etag标签,这个不够先进):

    看看erlang虚拟机里inets服务启动了哪些“进程”(这个进程是erlang虚拟机BEAM定义的进程,不是操作系统的进程):

    <0.40.0>              application_master:init/4              233       41    0
                          application_master:main_loop/2           6
    <0.41.0>              application_master:start_it/4          233       49    0
                          application_master:loop_it/4             5
    <0.42.0>              supervisor:inets_sup/1                 233      308    0
    inets_sup             gen_server:loop/6                        9
    <0.43.0>              supervisor:ftp_sup/1                   233       52    0
    ftp_sup               gen_server:loop/6                        9
    <0.44.0>              supervisor:httpc_sup/1                 233      171    0
    httpc_sup             gen_server:loop/6                        9
    <0.45.0>              supervisor:httpc_profile_sup/1         233      122    0
    httpc_profile_sup     gen_server:loop/6                        9
    <0.46.0>              httpc_manager:init/1                   233       78    0
    httpc_manager         gen_server:loop/6                        9
    <0.47.0>              supervisor:httpc_handler_sup/1         233       52    0
    httpc_handler_sup     gen_server:loop/6                        9
    <0.48.0>              supervisor:httpd_sup/1                 987      426    0
    httpd_sup             gen_server:loop/6                        9
    <0.49.0>              supervisor:tftp_sup/1                  233       52    0
    tftp_sup              gen_server:loop/6                        9
    <0.50.0>              supervisor:httpd_instance_sup/1        987      770    0
    httpd_instance_sup__1 gen_server:loop/6                        9
    <0.51.0>              supervisor:httpd_connection_sup/1      610     1163    0
    httpd_connection_sup_ gen_server:loop/6                        9
    <0.52.0>              supervisor:httpd_acceptor_sup/1        610      420    0
    httpd_acceptor_sup__1 gen_server:loop/6                        9
    <0.53.0>              httpd_acceptor:acceptor_init/8        1598     3494    0
                          prim_inet:accept0/2                     17
    <0.54.0>              supervisor:httpd_misc_sup/1            233       41    0
    httpd_misc_sup__192_1 gen_server:loop/6                        9
    <0.55.0>              httpd_manager:init/1                  2586     5838    0
    httpd__192_168_178_13 gen_server:loop/6                        9
    <0.56.0>              erlang:apply/2                         233      310    0
                          file_io_server:server_loop/1             3
    <0.57.0>              erlang:apply/2                         233      308    0
                          file_io_server:server_loop/1             3
    <0.58.0>              erlang:apply/2                        2586     6748    0
                          file_io_server:server_loop/1             3
    <0.61.0>              httpd_request_handler:init/1          2586    23440    0
                          gen_server:loop/6                        9
    <0.62.0>              httpd_request_handler:init/1          4185    12550    0
                          gen_server:loop/6                        9
    <0.63.0>              httpd_request_handler:init/1          4185     6476    0
                          gen_server:loop/6                        9
    <0.64.0>              httpd_request_handler:init/1          2586     6756    0
                          gen_server:loop/6                        9

    有几个进程比较多余,比如httpc,和tftp,这里不需要。

  • 相关阅读:
    解决PKIX:unable to find valid certification path to requested target 的问题
    Linux 上的常用文件传输方式介绍与比较
    用VNC远程图形化连接Linux桌面的配置方法
    红帽中出现”This system is not registered with RHN”的解决方案
    linux安装时出现your cpu does not support long mode的解决方法
    CentOS SSH配置
    es6扩展运算符及rest运算符总结
    es6解构赋值总结
    tortoisegit安装、clon、推送
    es6环境搭建
  • 原文地址:https://www.cnblogs.com/andypeker/p/4631120.html
Copyright © 2011-2022 走看看