VPS安装H2o替代Nginx - 开发说
当前位置: 主页 » Nginx » VPS安装H2o替代Nginx

VPS安装H2o替代Nginx

      2017年05月17日   阅读 1,688 次     0 评论   Tags: ·

H2o官方介绍:H2O is a new generation HTTP server that provides quicker response to users with less CPU utilization when compared to older generation of web servers. Designed from ground-up, the server takes full advantage of HTTP/2 features including prioritized content serving and server push, promising outstanding experience to the visitors of your web site.大致意思就是,老子比nginx还牛逼,支持HTTP2,支持server_push,更多进官网了解:https://h2o.examp1e.net/index.html

官方放了一张和nginx的对比图,看图确实比nginx快了不止一小点!!!:

8mbps100msec-nginx195-h2o150.png

  • 优点:速度快,特别在静态资源上,支持http2,支持server push,配置方便,不能隐藏版本号,有RPM包
  • 缺点:包比nginx大,对rewrite支持不是很友好,nginx对rewrite支持比较好,nginx不支持server push。

安装,我用rpm安装:

[root@kaifashuo h2o]# vi /etc/yum.repos.d/h2o.repo 
#bintray-tatsushid-h2o-rpm - packages by tatsushid from Bintray
[bintray-tatsushid-h2o-rpm]
name=bintray-tatsushid-h2o-rpm
#If your system is CentOS
baseurl=https://dl.bintray.com/tatsushid/h2o-rpm/centos/$releasever/$basearch/
#If your system is Fedora
#baseurl=https://dl.bintray.com/tatsushid/h2o-rpm/fedora/$releasever/$basearch/
gpgcheck=0
repo_gpgcheck=0
enabled=1

[root@kaifashuo ~]# yum install h2o
Loaded plugins: fastestmirror
bintray-tatsushid-h2o-rpm                                                                                                             | 1.3 kB  00:00:00     
bintray-tatsushid-h2o-rpm/7/x86_64/primary                                                                                            | 5.7 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: centos.sonn.com
 * epel: mirror.hmc.edu
 * extras: centos.mirror.lstn.net
 * remi-safe: mirrors.mediatemple.net
 * rpmforge: mirror.hmc.edu
 * updates: centos.mirror.ndchost.com
bintray-tatsushid-h2o-rpm                                                                                                                              40/40
Resolving Dependencies
--> Running transaction check
---> Package h2o.x86_64 0:2.2.2-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                      Arch                            Version                               Repository                                          Size
=============================================================================================================================================================
Installing:
 h2o                          x86_64                          2.2.2-1.el7                           bintray-tatsushid-h2o-rpm                          2.6 M

Transaction Summary
=============================================================================================================================================================
Install  1 Package

Total download size: 2.6 M
Installed size: 6.2 M
Is this ok [y/d/N]: y
Downloading packages:
h2o-2.2.2-1.el7.x86_64.rpm                                                                                                            | 2.6 MB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : h2o-2.2.2-1.el7.x86_64                                                                                                                    1/1 
  Verifying  : h2o-2.2.2-1.el7.x86_64                                                                                                                    1/1 

Installed:
  h2o.x86_64 0:2.2.2-1.el7                                                                                                                                   

Complete!

启动、关闭、加入开机启动

systemctl enable h2o.service
systemctl start h2o.service
systemctl restart h2o.service
systemctl stop h2o.service

配置文件:采用Mruby和YAML风格,不敏感,如果配置出错,错误提示比较好!

mruby is a lightweight implementation of the Ruby programming language. With H2O, users can implement their own request handling logic using mruby, either to generate responses or to fix-up the request / response.算了,不翻译了,自己瞧吧~~~

[root@kaifashuo h2o]# vi /etc/h2o/h2o.conf

user: nobody
hosts:
  "kaifashuo.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect: https://www.kaifashuo.com/
  "kaifashuo.com:443":
    listen:
      port: 443
      ssl: &default_ssl
        minimum-version: TLSv1.2
        cipher-suite: EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5
        certificate-file: /etc/letsencrypt/live/kaifashuo.com/fullchain.pem
        key-file:         /etc/letsencrypt/live/kaifashuo.com/privkey.pem
    paths:
      "/":
        mruby.handler: |
          Proc.new do |env|
            headers = {}
            if /\.(ico|gif|bmp|jpg|jpeg|png|swf|js|css|mp3)\z/.match(env["PATH_INFO"])
               headers["cache-control"] = "max-age=864000"
            end
            [399, headers, []]
          end

        file.dir: /home/kaifashuo
        redirect:                     # if not found, internally redirect to /index.php/
          url: /index.php/
          internal: YES
          status: 307

file.custom-handler:                  # connect to external FastCGI server listening to /tmp/fcgi.sock
  extension: .php
  fastcgi.connect:
    port: /dev/shm/php7-fpm.sock
    type: unix

gzip: OFF
http1-upgrade-to-http2: ON
file.dirlisting: off
file.send-compressed: on
limit-request-body: 1024
file.mime.addtypes:
   "text/html; charset=utf-8": .html

header.unset: "X-Powered-By"
http2-idle-timeout: 60
http2-max-concurrent-requests-per-connection: 50
http2-latency-optimization-max-additional-delay: 0.1
http2-latency-optimization-max-cwnd: 65535
header.add: "cache-control: max-age=50000000, public"
header.add: "strict-transport-security: max-age=50000000; includesubdomains; preload"
header.add: "x-content-type-options: nosniff"
header.add: "x-frame-options: deny"
header.add: "x-xss-protection: 1; mode=block"

access-log: /var/log/h2o/access-log
error-log: /var/log/h2o/error-log
pid-file: /var/run/h2o.pid
http2-reprioritize-blocking-assets: ON   # performance tuning option

PS:本博现在用h2o,希望大家体验一下,h2o不就是水吗?看看到底水不水,做个留言反馈~~

  • 版权声明:本文版权归开发说和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 开发说 整理发布,欢迎转载,转载请带版权。

  • 来源:开发说 ( https://www.kaifashuo.com/ ),提供主机优惠信息深度测评和服务器运维编程技术。
  • 链接:https://www.kaifashuo.com/82.html
  • 评论(0

    1. 还没有任何评论,你来说两句吧

    发表回复

    您的邮箱地址不会被公开。 必填项已用 * 标注