Giter VIP home page Giter VIP logo

Comments (10)

769344359 avatar 769344359 commented on July 20, 2024 2
            access_by_lua_block {
                local orange = context.orange
                orange.access()
            }

添加一行orange.init_cookies()
改成

            access_by_lua_block {
                local orange = context.orange
                orange.init_cookies()      
                orange.access()
            }

@magaofei

from orange.

zhangbao0325 avatar zhangbao0325 commented on July 20, 2024

麻烦贴一下你的divide插件最终生成的json配置信息以及你的nginx配置文件?

from orange.

sydowma avatar sydowma commented on July 20, 2024
worker_processes auto;
user root;

events {
    worker_connections  4096;
}

# optional: path of orange.conf
env ORANGE_CONF;

http {
    resolver 114.114.114.114; # replace it with your favorite config
    charset UTF-8;
    include ./mime.types;

    log_format  main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$request_time" "$ssl_protocol" "$ssl_cipher" "$http_x_forwarded_for"'
    '"$upstream_addr" "$upstream_status" "$upstream_response_length" "$upstream_response_time"';

    access_log  ./logs/access.log  main;
    error_log ./logs/error.log debug;

    sendfile        on;
    keepalive_timeout  65;

    upstream default_upstream {
        server localhost:8001;
    }
    upstream baidu {
        server baidu.com;
    }
    #
    # Config client_body_buffer_size equal client_max_body_size for enforcing in-memory buffering of the whole request body
    # ref: https://github.com/openresty/lua-nginx-module/issues/521
    #
    # official instruct docs http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
    #
    client_body_buffer_size 1m;
    client_max_body_size 1m;

    #----------------------------Orange configuration-----------------------------
    lua_package_path  "$prefix/deps/share/lua/5.1/?.lua;$prefix/deps/share/lua/5.1/orange/?.lua;$prefix/?.lua;/usr/share/lua/5.1/?.lua;/usr/local/lor/?.lua;;";
    lua_package_cpath "$prefix/deps/lib64/lua/5.1/?.so;$prefix/deps/lib/lua/5.1/?.so;/usr/lib64/lua/5.1/?.so;;";
    lua_code_cache on;

    lua_shared_dict orange_data 20m; # should not removed. used for orange data, e.g. plugins configurations..

    lua_shared_dict status 1m; # used for global statistic, see plugin: stat
    lua_shared_dict waf_status 1m; # used for waf statistic, see plugin: waf
    lua_shared_dict monitor 10m; # used for url monitor statistic, see plugin: monitor
    lua_shared_dict rate_limit 10m; # used for rate limiting count, see plugin: rate_limiting
    lua_shared_dict property_rate_limiting 10m; # used for rate limiting count, see plugin: rate_limiting



    init_by_lua_block {
        local orange = require("orange.orange")
        local env_orange_conf = os.getenv("ORANGE_CONF")
        print(string.char(27) .. "[34m" .. "[INFO]" .. string.char(27).. "[0m", [[the env[ORANGE_CONF] is ]], env_orange_conf)

        -- Here, you can also use the absolute path, eg: local confige_file = "/home/openresty/orange/conf/orange.conf"
        local config_file = env_orange_conf or ngx.config.prefix().. "/conf/orange.conf"
        local config, store = orange.init({
            config = config_file
        })

        -- the orange context
        context = {
            orange = orange,
            store = store,
            config = config
        }
    }

    init_worker_by_lua_block {
        local orange = context.orange
        orange.init_worker()
    }

    # main server
    server {
        listen       80;
        #server_name  my_domain.com;

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location / {
            set $upstream_host $host;
            set $upstream_url 'http://default_upstream';

            rewrite_by_lua_block {
                local orange = context.orange
                orange.redirect()
                orange.rewrite()
            }

            access_by_lua_block {
                local orange = context.orange
                orange.access()
            }

            # proxy
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Scheme $scheme;
            proxy_set_header Host $upstream_host;
            proxy_pass $upstream_url;


            header_filter_by_lua_block {
                local orange = context.orange
                orange.header_filter()
            }

            body_filter_by_lua_block {
                local orange = context.orange
                orange.body_filter()
            }

            log_by_lua_block {
                local orange = context.orange
                orange.log()
            }
        }

        location /robots.txt {
            return 200 'User-agent: *\nDisallow: /';
        }
    }

    # default upstream server
    server {
        listen 8001;
        server_name localhost 127.0.0.1;
        access_log ./logs/default_upstream_access.log main;
        error_log ./logs/default_upstream_error.log;

        location / {
            content_by_lua_block {
                local json = require "cjson"
                ngx.status = 200
                ngx.say("Host: "..ngx.var.host .. "  URI: " .. ngx.var.uri)
                ngx.say('[Query Params]', json.encode(ngx.req.get_uri_args()))
                ngx.req.read_body()
                ngx.say('[Post Params]', json.encode(ngx.req.get_post_args()))
                ngx.say('[Header Params]', json.encode(ngx.req.get_headers()))
            }
        }
    }


    # orange dashboard server
    server {
        listen       9999;
        stub_status on;
        #server_name  localhost;
        access_log ./logs/dashboard_access.log main;
        error_log ./logs/dashboard_error.log info;

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location /robots.txt {
            return 200 'User-agent: *\nDisallow: /';
        }

        # dashboard的静态文件
        location ~* /static/(.*) {
            alias ./dashboard/static/$1;
        }

        location / {
            set $template_root '';
            content_by_lua_block {
                context.views_path = ngx.config.prefix() .. "/dashboard/views"
                local main = require("dashboard.main")
                main:run()
            }
        }
    }

    # api server
    server {
        listen       7777;
        #server_name  localhost;
        access_log ./logs/api_access.log main;
        error_log ./logs/api_error.log info;

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location /robots.txt {
            return 200 'User-agent: *\nDisallow: /';
        }

        location / {
            content_by_lua_block {
                local main = require("api.main")
                main:run()
            }
        }
    }

}

from orange.

sydowma avatar sydowma commented on July 20, 2024
{
  "divide.enable": true,
  "divide.selectors": {
    "e4ed6bee-4666-47d0-a780-1a6c1a648ad8": {
      "time": "2020-01-02 16:13:48",
      "enable": true,
      "rules": [
        "e24e601b-5f1e-46a1-ae16-0a28afddf267"
      ],
      "id": "e4ed6bee-4666-47d0-a780-1a6c1a648ad8",
      "judge": [],
      "name": "hello",
      "handle": {
        "continue": false,
        "log": true
      },
      "type": 0
    }
  },
  "divide.selector.e4ed6bee-4666-47d0-a780-1a6c1a648ad8.rules": [
    {
      "id": "e24e601b-5f1e-46a1-ae16-0a28afddf267",
      "log": true,
      "name": "hello1",
      "upstream_host": "",
      "upstream_url": "http://baidu",
      "judge": {
        "type": 0,
        "conditions": [
          {
            "value": "test1",
            "name": "env",
            "operator": "=",
            "type": "Cookie"
          }
        ]
      },
      "enable": true,
      "time": "2020-01-06 16:00:08",
      "extractor": {
        "extractions": [],
        "type": 2
      }
    }
  ],
  "divide.meta": {
    "selectors": [
      "e4ed6bee-4666-47d0-a780-1a6c1a648ad8"
    ]
  }
}

from orange.

zhangbao0325 avatar zhangbao0325 commented on July 20, 2024

配置没看出啥问题,可能是你curl的方式不对
你试试以下两种方式:
curl www.baidu.com -x 127.0.0.1:80 --cookie "env=test1"
curl www.baidu.com -x 127.0.0.1:80 -H 'Cookie:env=test1"'
另外,你的OR是那个版本?

from orange.

sydowma avatar sydowma commented on July 20, 2024

配置没看出啥问题,可能是你curl的方式不对
你试试以下两种方式:
curl www.baidu.com -x 127.0.0.1:80 --cookie "env=test1"
curl www.baidu.com -x 127.0.0.1:80 -H 'Cookie:env=test1"'
另外,你的OR是那个版本?

v0.8 和 v0.8.1都试过,不行

from orange.

sydowma avatar sydowma commented on July 20, 2024

image
我分别设置 Header 获取和 Cookie ,Header 是可以分流的,Cookie获取不到

from orange.

sydowma avatar sydowma commented on July 20, 2024
            access_by_lua_block {
                local orange = context.orange
                orange.access()
            }

添加一行orange.init_cookies()
改成

            access_by_lua_block {
                local orange = context.orange
                orange.init_cookies()      
                orange.access()
            }

@magaofei

@769344359 可以了,感谢,不过这一行为什么没有出现的官方的 nginx.conf

from orange.

769344359 avatar 769344359 commented on July 20, 2024

好像是cookie模块没有初始化 @magaofei

from orange.

sydowma avatar sydowma commented on July 20, 2024

好像是cookie模块没有初始化 @magaofei

@769344359 那这一行是必须的吧?我提交了一个PR,添加上去了

from orange.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.