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

posted on   荣锋亮  阅读(57)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-02-01 mtools mongo 日志分析的利器
2023-02-01 nginx agent 来自官方的nginx 配置管理&监控方案
2022-02-01 Building a Sync Engin
2022-02-01 grouparoo 基于nodejs 的开源反向ETL 工具
2022-02-01 Castled 源码解析 - container 模块说明
2021-02-01 cube.js 上下文实践的一些说明
2020-02-01 Performance Profiling Zeebe

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示