分发层nginx,lua应用,会将商品id,商品店铺id,都转发到后端的应用nginx
nginx+lua+java多级缓存流程
修改分发层nginx
- 分发层nginx
eshop-cache03<192.168.0.108>
,vi /usr/hello/hello.conf
location /product {
default_type 'text/html';
# lua_code_cache off;
content_by_lua_file /usr/hello/lua/distribute.lua;
}
- 修改
lua
脚本:vi /usr/hello/lua/distribute.lua
local uri_args = ngx.req.get_uri_args()
local productId = uri_args["productId"]
local shopId = uri_args["shopId"]
local host = {
"192.168.0.106", "192.168.0.107"}
local hash = ngx.crc32_long(productId)
local index = (hash % 2) + 1
local backend = "http://"..host[index]
local requestPath = uri_args["requestPath"]
requestPath = "/"..requestPath.."?productId="..productId.."&shopId="..shopId
local http = require("resty.http")
local httpc = http.new()
local resp, err = httpc:request_uri(backend, {
method = "GET",
path = requestPath,
keepalive=false