4-5 HTTP2的优势和Nginx配置HTTP2的简单使用
2018-12-07 本文已影响0人
伯纳乌的追风少年
Http2的优势:


http2的配置:
proxy_cache_path cache levels=1:2 keys_zone=my_cache:10m;
server {#由http跳转到https
listen 80 default_server;
listen [::]:80 default_server;
server_name test.com;
return 302 https://$server_name$request_uri;
}
server {
listen 443 http2;
server_name test.com;
http2_push_preload on;#开启http2的push
ssl on;
ssl_certificate_key /usr/local/etc/nginx/certs/localhost-privkey.pem;
ssl_certificate /usr/local/etc/nginx/certs/localhost-cert.pem;
location / {
proxy_cache my_cache;
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $host; #nginx对http请求的host进行转发
}
}
http2的性能测试网站:https://http2.akamai.com/demo/http2-lab.html