[記錄點滴]OpenResty 支持http v2的問題


[記錄點滴]OpenResty 支持http v2的問題

0x00 摘要

記錄一次OpenResty支持http v2的問題排查。

0x01 問題

錯誤現象:無法上傳圖片,后台log是http v2 not supported yet

以為是后台沒有開啟http v2,於是開始排查。

0x02 排查

nginx

nginx顯示支持 v2

/usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.11.2.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC)
built with OpenSSL 1.0.2k  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl/include' --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.8 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl/lib' --with-pcre-jit --with-ipv6 --with-stream --with-stream_ssl_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-file-aio --with-dtrace-probes --with-http_ssl_module

curl

用curl來驗證,也顯示支持v2

curl --http2 -I https://xxx/
HTTP/2 500
server: nginx
content-type: application/octet-stream
content-length: 11

需要看看curl是否支持http2,顯示也支持

curl -V
curl 7.55.1 (x86_64-pc-linux-gnu) libcurl/7.55.1 OpenSSL/1.0.1 zlib/1.2.3.4 nghttp2/1.26.0-DEV librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy

nginx源碼

nginx源碼中,沒有搜索到這個字符串http v2 not supported yet

Openresty編譯https

懷疑是Openresty沒有編譯進去http2,於是重新編譯

./configure --prefix=/usr/local/openresty_http_v2 \
            --with-pcre-jit \
            --with-ipv6 \
            --with-http_iconv_module \
            --with-luajit \
      --with-http_v2_module \
            --with-openssl=/home/xxx/openssl-1.0.2l\
            -j2 \


            --with-http_postgres_module \ --------------> 這個不行

但是這個版本也不行,同樣的錯誤。

0x03 resty.upload代碼排查

上傳圖片使用resty.upload

local UPLOAD = require "resty.upload"
local form,err = UPLOAD:new(chunk_size)
local typ, res, err = form:read()

所以我們去resty.upload代碼看,發現使用了ngx.req.socket

local req_socket = ngx.req.socket
local sock, err = req_socket()
if not sock then
	return nil, err
end

0x04 OpenResty源碼

下載openresty源碼,在ngx_http_lua_req_socket函數中,確實有這個字符串

static int ngx_http_lua_req_socket(lua_State *L) {
#if (NGX_HTTP_V2)
    if (r->stream) {
        return luaL_error(L, "http v2 not supported yet");
    }
#endif
}

這明明是:在http v2情況下,socket不支持stream好不好!

0x05 解決

nginx.conf中,取消了http2的配置。這樣客戶端就知道后台只支持httpv1.1,就按照1.1來傳輸,就可以了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM