How To Customize Your Nginx Server Name
- src/core/nginx.h
#define NGINX_VER "MYWS/“ NGINX_VERSION
- http/ngx_http_special_response.c
"<hr><center>MYWS</center>” CRLF
- http/ngx_http_header_filter_module.c
static u_char ngx_http_server_string[] = "Server: MYWS" CRLF;
- src/http/v2/ngx_http_v2_filter_module.c
static const u_char nginx[5] = "\x84\xd1\xcf\x96\xef";
第4点是为http2 做的修改.字节码生成:
package main
import (
"fmt"
"golang.org/x/net/http2/hpack"
)
func main() {
fmt.Println("nginx", "→", Encode("ithothub"))
fmt.Println("nginx", "→", Encode("nginx"))
fmt.Println("apache", "→", Encode("apache"))
}
func Encode(s string) string {
var result string
hd := hpack.AppendHuffmanString(nil, s)
hl := hpack.HuffmanEncodeLength(s) | 0x80
result += RenderByte(byte(hl))
for _, b := range hd {
result += RenderByte(b)
}
return result
}
func Decode(s string) string {
data := []byte(s)
result, _ := hpack.HuffmanDecodeToString(data[1:])
return result
}
func RenderByte(b byte) string {
return fmt.Sprintf("\\x%x", b)
}
评论前必须登录!
注册