Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx parse cannot parse lua script #9

Open
lwfcatch opened this issue Jan 27, 2022 · 1 comment
Open

nginx parse cannot parse lua script #9

lwfcatch opened this issue Jan 27, 2022 · 1 comment

Comments

@lwfcatch
Copy link

lwfcatch commented Jan 27, 2022

server {
    server_name test.xxxx.com;
    listen 80;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $http_x_forwarded_protocol;
    proxy_set_header X-Rewrite-URL $request_uri;

    location /test/ {

        set_by_lua_block $foo {
            local ok, err = pcall(require("phases_modules").set_process)
            if not ok then
            local emsg = "[LUA Framework], set_process failed."
            ngx.log(ngx.ERR, emsg, err)
            end
        }

        if ($request_uri !~* ^/test-resource/goofy/(.*)$ ) {
            rewrite ^/test-resource/(.*)$ /test-resource/goofy/$1 break;
        }

        proxy_pass http://test2.xxx.com;
    }
}
func main() {
	nginxConfFromPath, err := configuration.NewConfigurationFromPath("/Users/catch/Desktop/test.nginx")
	if err != nil {
		panic(err)
	}
	fmt.Println(string(nginxConfFromPath.Json()))
}

panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader.(*loader).loadFromConfigPosition(0xc000023040, 0x41a1fab, 0x23, 0x0, 0x0, 0x0, 0x0)
/Users/catch/go/src/github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader/loader.go:249 +0xd45
github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader.(*loader).LoadFromFilePath(0xc000023040, 0x41a1fab, 0x23, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/catch/go/src/github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/loader/loader.go:43 +0x32f
github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration.NewConfigurationFromPath(0x41a1fab, 0x23, 0xc000117f78, 0x400b465, 0xc000070058, 0x0)
/Users/catch/go/src/github.com/ClessLi/bifrost/pkg/resolv/V2/nginx/configuration/configuration.go:292 +0x92
main.main()
/Users/catch/Documents/code/deliver/go/plugin.go:119 +0x3a

@ClessLi
Copy link
Owner

ClessLi commented Jan 27, 2022

The nginx.Parser does not support fields or contexts in the format of Lua Scripts currently. You can consider first to separate Lua Scripts into script files and set a parser.Key for it. The sample configuration is as follows:

...
location /test/ {

        set_by_lua_block_file ../block.lua;
...

At present, I am reconstructing the Heimdallr-reborn project. After completion, I will consider allowing Bifrost to support custom format fields or contexts such as Lua Scripts; Or if you have a better solution, you are welcome to submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants