Closed transtone closed 6 months ago
location /api/ { set $userId ''; set $companyCode ''; access_by_lua_block { local cjson = require "cjson" local response = {} response['code'] = 401 response['msg'] = "请登录!" response['result'] = ngx.var.userId ngx.status = 401 ngx.say(cjson.encode(response)) } add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Credentials' false always; add_header 'Access-Control-Allow-Methods' 'OPTIONS,GET,PUT,POST,PATCH,DELETE' always; add_header 'Access-Control-Allow-Headers' 'User-Agent,Tenant-Code,Content-Type,Token,Timestamp,Referer,Origin,Connection' always; if ($request_method = 'OPTIONS') { return 204; } proxy_hide_header Access-Control-Allow-Origin; proxy_pass http://127.0.0.1:18080/; proxy_redirect default; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_read_timeout 3600; proxy_set_header User-Id $userId; proxy_set_header Company-Code $companyCode; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
openresty/openresty:1.25.3.1-centos
I want it return 401, but it proxied to 127.0.0.1:18080. what can I do?
127.0.0.1:18080
==============
must add ngx.eof() after ngx.say('say something')
ngx.eof()
ngx.say('say something')
openresty/openresty:1.25.3.1-centos
I want it return 401, but it proxied to
127.0.0.1:18080
. what can I do?==============
must add
ngx.eof()
afterngx.say('say something')