V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
alect
V2EX  ›  分享发现

apache2.4.17 启用 http/2 成功,附上步骤以及测试网站

  •  
  •   alect · 2015-10-15 21:25:42 +08:00 · 10015 次点击
    这是一个创建于 3087 天前的主题,其中的信息可能已经有所发展或是发生改变。
    apache 2.4.17 昨天发布,加入了实验性的 http/2,捣鼓了一天才弄清楚应该怎么玩。。
    本人环境 centos7.步骤如下:
    因为 http/2 依赖 libnghttp2 库,需要先安装,此外还需要 openssl 版本大于 1.0.2
    如果你没法 yum 安装,需要先安装 epel-release
    yum install libnghttp2-devel
    重新编译 apache ,加上参数 --enable-http2
    修改 vhost ,加入 Protocols h2 http/1.1 到 vhost 里面即可

    <VirtualHost x.x.x.x:443 >
    Protocols h2 http/1.1
    ……
    ……
    ……
    </VirtualHost>

    此外还可以在 vhost 的 80 端口那一段加上 Protocols h2c http/1.1
    以便以后可以让 http 也能支持 h2,(然并卵,目前没有浏览器支持 80 端口的 h2 协议。。
    参考: https://icing.github.io/mod_h2/howto.html

    附上自建的测试网站:
    http://http1.xxshe.com/ 80 端口普通加载测试
    https://http1.xxshe.com/ 未启用 http2 的加载测试
    https://http2.xxshe.com/ 启用了 http2 的加载测试
    第 1 条附言  ·  2015-10-16 00:36:23 +08:00
    测试得知,新版 apache 有个 bug ,在同一个 ip 下面启用野卡 wildcard ssl 证书的时候,配置多个二级域名的情况下,很大几率会导致访问这几个二级域名失败,提示 Misdirected Request

    The client needs a new connection for this request as the requested host name does not match the Server Name Indication (SNI) in use for this connection.

    nginx 则没有这个问题,应该是 apache 的 bug
    第 2 条附言  ·  2015-10-16 02:02:19 +08:00


    去扒了 akamai 的测试代码,放自己网站上了。。。效果果然很显著。。

    测试网址: http://http1.xxshe.com/demo/
    18 条回复    2015-12-10 19:36:03 +08:00
    bigtan
        1
    bigtan  
       2015-10-15 21:41:31 +08:00
    请问如何重新编译?
    MrGba2z
        2
    MrGba2z  
       2015-10-15 21:42:43 +08:00
    这图标按字母排序哈哈哈是怕引起争议吗
    alect
        3
    alect  
    OP
       2015-10-15 22:00:41 +08:00
    @bigtan 呃,编译 apache 这个帮不了你。。
    @MrGba2z 哈哈,直接字母名称排序。。倒是没考虑过争议问题
    ljbha007
        4
    ljbha007  
       2015-10-15 22:10:22 +08:00
    这个域名。。。
    Kisesy
        5
    Kisesy  
       2015-10-15 22:12:06 +08:00
    h2 确实快。。
    wjfz
        6
    wjfz  
       2015-10-15 22:45:54 +08:00 via Android
    这域名……
    alect
        7
    alect  
    OP
       2015-10-15 22:50:45 +08:00
    @ljbha007 @wjfz
    主站 www.hexieshe.com 和邪社 后来申请 www.xxshe.com 当备用,和谐=xx
    MrGba2z
        8
    MrGba2z  
       2015-10-15 23:10:20 +08:00
    @alect 原来你是和邪社的站长!!我关注贵站很久了
    alect
        9
    alect  
    OP
       2015-10-15 23:12:09 +08:00
    @MrGba2z 看你头像应该就是 ACG 爱好者,:-D
    shmilyin
        10
    shmilyin  
       2015-10-15 23:14:06 +08:00
    我这 http 更快
    pmpio
        11
    pmpio  
       2015-10-15 23:15:32 +08:00
    http2 确实要快一些。。。。
    bigtan
        12
    bigtan  
       2015-10-15 23:36:51 +08:00
    @alect 那就等 sid 源的打包吧
    ryd994
        13
    ryd994  
       2015-10-16 07:54:20 +08:00
    @bigtan 如果不强求 apache 的话用 nginx , nginx mainline 上个月开始就有了:
    http://nginx.org/packages/mainline/debian/
    mjever
        14
    mjever  
       2015-10-16 09:22:33 +08:00
    我这 http 更快+1
    GPU
        15
    GPU  
       2015-10-16 09:49:49 +08:00
    http 更快+2
    yyx007
        16
    yyx007  
       2015-12-09 17:22:30 +08:00
    我搭了 apache2.4.17 openssl1.0.2
    之后 vhost 加了那条 ./configure --enable-http2 也做了。但是就是没有启用你知道怎么回事吗
    自签证书 https://test.meishi.work
    alect
        17
    alect  
    OP
       2015-12-09 21:10:12 +08:00
    @yyx007 编译 openssl 我这是安装到 /usr/local/lib_http2
    wget http://openssl.org/source/openssl-1.0.2d.tar.gz
    tar xzf openssl-1.0.2d.tar.gz
    cd openssl-1.0.2d
    ./config --prefix=/usr/local/lib_http2 no-ssl2 no-ssl3 zlib-dynamic
    make depend
    make install

    编译 Apache ,默认的 "--with-ssl=/usr" \ 改为
    "--enable-http2" \
    "--enable-ssl-staticlib-deps" \
    "--with-ssl=/usr/local/lib_http2" \

    然后修改 httpd.conf
    echo 'ProtocolsHonorOrder On' >> /etc/httpd/conf/extra/httpd-includes.conf
    echo 'Protocols h2 h2c http/1.1' >> /etc/httpd/conf/extra/httpd-includes.conf
    yyx007
        18
    yyx007  
       2015-12-10 19:36:03 +08:00
    恩恩。后面成功了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5190 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 01:21 · PVG 09:21 · LAX 18:21 · JFK 21:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.