xdm 好,我是个前端,运维方面的菜鸡,请教大家一下
我用 openresty 搭建了个简陋版本的灰度切换方案,但是 lua 脚本运行之后好像出了点问题
-------------------------test.conf start-----------------------------
upstream production_server {
server 123.123.123.123:80;
}
upstream grayscale_server {
server 456.456.456.456:80;
}
server {
listen 80;
server_name localhost;
lua_code_cache off;
set $default_stream "production_server";
set $grayscale_stream "grayscale_server";
# 运行脚本读取策略
access_by_lua_file /usr/local/openresty/lua/main.lua;
location / {
default_type text/html;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass $scheme://$default_stream;
proxy_next_upstream http_500 http_503 error;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/openresty/nginx/html;
}
}
-------------------------test.conf end-----------------------------
-------------------------main.lua start-----------------------------
local redisutils = require("redisutils")
local controller = require("controller")
local red = redisutils.redisClient()
local params = ngx.req.get_uri_args()
local userId = params.userId
if red then
local is_grayscale = controller.checkUserId(red, userId)
if is_grayscale then
ngx.var.default_stream = ngx.var.grayscale_stream
end
redisutils.closeRedis(red)
end
-------------------------main.lua end-----------------------------
我把$default_stream 直接替换为“production_server” 或 “grayscale_server” 都没有问题
但是 lua 运行后,大概是这一句 ngx.var.default_stream = ngx.var.grayscale_stream
index.html 中的 js 和 css 等使用相对路径(“/js/xxx.js”)的资源都似乎回源到了代理机器本身,从而最终找不到资源
如果哪位大佬有办法解决,希望不吝赐教一下,或者说有更好的方法也可以。
感谢!!!
我用 openresty 搭建了个简陋版本的灰度切换方案,但是 lua 脚本运行之后好像出了点问题
-------------------------test.conf start-----------------------------
upstream production_server {
server 123.123.123.123:80;
}
upstream grayscale_server {
server 456.456.456.456:80;
}
server {
listen 80;
server_name localhost;
lua_code_cache off;
set $default_stream "production_server";
set $grayscale_stream "grayscale_server";
# 运行脚本读取策略
access_by_lua_file /usr/local/openresty/lua/main.lua;
location / {
default_type text/html;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass $scheme://$default_stream;
proxy_next_upstream http_500 http_503 error;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/openresty/nginx/html;
}
}
-------------------------test.conf end-----------------------------
-------------------------main.lua start-----------------------------
local redisutils = require("redisutils")
local controller = require("controller")
local red = redisutils.redisClient()
local params = ngx.req.get_uri_args()
local userId = params.userId
if red then
local is_grayscale = controller.checkUserId(red, userId)
if is_grayscale then
ngx.var.default_stream = ngx.var.grayscale_stream
end
redisutils.closeRedis(red)
end
-------------------------main.lua end-----------------------------
我把$default_stream 直接替换为“production_server” 或 “grayscale_server” 都没有问题
但是 lua 运行后,大概是这一句 ngx.var.default_stream = ngx.var.grayscale_stream
index.html 中的 js 和 css 等使用相对路径(“/js/xxx.js”)的资源都似乎回源到了代理机器本身,从而最终找不到资源
如果哪位大佬有办法解决,希望不吝赐教一下,或者说有更好的方法也可以。
感谢!!!