Created
June 27, 2016 14:00
-
-
Save jannson/05a006bafea0ee34a9558786105dab82 to your computer and use it in GitHub Desktop.
openresty for nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 5000; | |
server_name netgear.ngrok.wang; | |
charset utf-8; | |
access_log logs/koolshare.access.log main; | |
error_log logs/error.koolshare.log info; | |
location / { | |
root /usr/local/openresty/nginx/webs/koolshare.github.io; | |
set_by_lua $callback ' | |
function get_callback() | |
local args = ngx.req.get_uri_args() | |
if type(args["callback"]) ~= "nil" and args["callback"] then | |
if type(args["callback"]) == "table" then | |
args["callback"] = args["callback"][#args["callback"]] | |
end | |
local callback = args["callback"] | |
if type(callback) == "nil" then | |
return nil | |
else | |
return callback | |
end | |
else | |
return nil | |
end | |
end | |
return get_callback() | |
'; | |
header_filter_by_lua ' | |
if ngx.var.callback ~= "" and (ngx.header["Content-Type"] == "application/javascript; charset=utf-8" or ngx.header["Content-Type"] == "application/javascript") then | |
ngx.header.content_length = nil | |
else | |
ngx.var.callback = nil | |
end | |
'; | |
body_filter_by_lua ' | |
if ngx.var.callback then | |
local resp_body = ngx.arg[1] | |
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. resp_body | |
if ngx.arg[2] then | |
ngx.arg[1] = ngx.var.callback .. "(" .. ngx.ctx.buffered .. ")" | |
return | |
end | |
ngx.arg[1] = nil | |
end | |
'; | |
} | |
location /incoming { | |
content_by_lua ' | |
local res = os.execute("/bin/sh /usr/local/openresty/nginx/webs/build/deploy.sh") | |
ngx.header.content_type = "text/html; charset=utf-8" | |
ngx.say(res) | |
ngx.exit(ngx.HTTP_OK) | |
'; | |
} | |
error_page 404 /404.html; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment