nginx+lua 設置跨域


nginx 配置:

                        header_filter_by_lua_file cros.lua;
                        access_by_lua '
                        if ngx.var.request_method == "OPTIONS" then
                        return 203
                        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"] = "86400"
      ngx.header["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS, DELETE"
      ngx.header["Content-Length"] = "0"
      ngx.header["Content-Type"] = "text/plain, charset=utf-8"
   end 
end

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM