nginx-go-crossplane nginx 配置解析包试用
以下是一个简单试用,学习下nginx-go-crossplane 的使用
参考代码
- nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root html;
index index.html index.htm;
}
location /files {
alias /opt/files;
add_header 'X-Content-Type-Options' 'nosniff';
autoindex on;
}
location /token/{
default_type text/html;
content_by_lua_block {
ngx.say([[this is a demo token]])
}
}
location /login {
default_type text/html;
content_by_lua_block {
login(ngx.req)
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
- 解析代码
main.go
package main
import (
"encoding/json"
"fmt"
"os"
crossplane "github.com/nginxinc/nginx-go-crossplane"
)
func main() {
path := os.Args[1]
payload, err := crossplane.Parse(path, &crossplane.ParseOptions{})
if err != nil {
panic(err)
}
b, err := json.Marshal(payload)
if err != nil {
panic(err)
}
fmt.Println(string(b))
}
- 解析效果
go run main.go ./nginx.conf | jq .
lua 模块部分问题(实际上参数,但是解析为了指令)
说明
目前对于部分解析是有问题的,比如上边的lua 集成的,github 上也有类似的issue 可以参考
参考资料
https://github.com/nginxinc/nginx-go-crossplane
https://github.com/nginxinc/nginx-go-crossplane/issues/32
https://github.com/nginxinc/crossplane/issues/85