nginx+lua 设置跨域
阅读原文时间:2023年07月11日阅读:2

nginx 配置:

                    header\_filter\_by\_lua\_file cros.lua;  
                    access\_by\_lua '  
                    if ngx.var.request\_method == "OPTIONS" then  
                    return  
                    end  
                    ';

cros.lua:

if string.find(ngx.var.http_origin,":8008") then //判断request的origin
ngx.header["Access-Control-Allow-Credentials"] = "true"
ngx.header["Access-Control-Allow-Origin"] = ngx.var.http_origin
ngx.header["Access-Control-Allow-Headers"] = "x-requested-with,content-type"
if ngx.var.request_method == "OPTIONS" then ngx.header["Access-Control-Max-Age"] = ""
ngx.header["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS, DELETE"
ngx.header["Content-Length"] = ""
ngx.header["Content-Type"] = "text/plain, charset=utf-8"
end
end

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器