openresty支持http2

上一篇 / 下一篇  2017-01-12 17:03:45 / 个人分类:nginx

最近项目中需要启用https,初期项目,也不想花那个冤枉钱买证书,就在wosign上申请了一个免费初级证书,其支持20个域名,免费三年 申请好证书后,会有一些列for xxx的zip,我们选用nginx的,里面有crt跟key文件,copy到serverweb server用的是openresty,之前编译的时候没有加--with-httpv2module参数,需要重新编译下,要想让http2启用,还得将openssl升级到1.0.2以上版本,但是不要使用1.1.0,因为1.1.0很多api做过更改,luangxmodule暂时不支持openssl 1.1.0版本

>wget https://www.openssl.org/source/openssl-1.0.2h.tar.gz
>tar zxvf openssl-1.0.2h.tar.gz

这里无需再进行编译,我们只需要源码,如果你想升级系统的openssl的话,就运行 openssl-1.0.2h/config 然后make,make install,再做几个类库连接即可

然后我们开始编译openresty
>./configure --prefix=/usr/local/openresty --with-luajit --with-http_v2_module --with-openssl=/tmp/openssl-1.0.2
>make
>make install

接下来修改nignx配置,使其支持https访问以及打开http2

>mkdir /usr/local/openresty/nginx/ssl

将刚传到服务器上的crt以及key文件复制到ssl目录
>cp /tmp/1_xxxx_bundle.crt /usr/local/openresty/nginx/ssl/xxx.crt
>cp /tmp/2_xxxx.key /usr/local/openresty/nginx/ssl/xxx.key
修改nginx.conf,增加433 server配置
server {  
        listen 443 ssl http2; //http2 协议启用
        ssl on;
        server_name xxx.xxx.xxx;
        ssl_certificate /usr/local/openresty/nginx/ssl/xxx.crt;
        ssl_certificate_key /usr/local/openresty/nginx/ssl/xxx.key;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2; #这里弃用sslv3协议,安全期间
           ssl_ciphers      EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
           ssl_prefer_server_ciphers   on;
           ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        index index.html index.htm;
        root /path/to;
        location / {
        }
        .....
}

然后重启下nginx,接着就开始访问吧 如何得知http2以及启用了,在chrome下可以通过开发者工具看到传输的protocol,方法,F12>在network那边,右键将protocol栏目勾选,再刷新下页面,当看到协议为h2时,便配置成功了

openresty下载:https://openresty.org/en/download.html

摘自:https://www.oliyo.com/openrety-work-with-http2/


TAG:

 

评分:0

我来说两句

jiahou166

jiahou166

立志要如山,行道要如水。不如山,不能坚定,不如水,不能曲达。

日历

« 2024-03-26  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 76018
  • 日志数: 87
  • 建立时间: 2012-04-02
  • 更新时间: 2021-05-29

RSS订阅

Open Toolbar