UNPKG

akamai-nginx

Version:

generate nginx config from akamai property

117 lines (87 loc) 3.47 kB
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type text/html; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; lua_package_path "/usr/local/openresty/nginx/conf/lua/?.lua;;"; server { lua_code_cache off; listen 80; server_name localhost; listen 443 ssl; ssl_certificate ssl/nginx.crt; ssl_certificate_key ssl/nginx.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { set $aka_origin_scheme ''; set $aka_origin_host ''; set $aka_origin_host_header ''; set $aka_origin_url ''; set $aka_deny_reason ''; set $aka_redirect_location ''; set $aka_redirect_code ''; set $aka_cache_ttl_seconds ''; set $aka_gzip 'off'; rewrite_by_lua_file conf/lua/akamai.lua; resolver 127.0.0.11 ipv6=off; proxy_ssl_verify off; proxy_ssl_server_name on; proxy_set_header Host $aka_origin_host_header; # proxy to origin proxy_pass $aka_origin_scheme://$aka_origin_host$aka_origin_url; header_filter_by_lua_block { -- log request headers -- local reqh = ngx.req.get_headers() -- for k, v in pairs(reqh) do -- ngx.log(ngx.ERR, "request header "..k.."="..v..";") -- end ngx.header["X-Accel-Expires"] = ngx.var.aka_cache_ttl_seconds -- manipulate response headers from origin local resh = ngx.ctx["aka_downstream_headers"] if (resh ~= nil) then for k, v in pairs(resh) do if (v[1] ~= "REGEX" or ngx.header[k] == nil) then ngx.header[k] = v[2] else ngx.header[k] = string.gsub(ngx.header[k], v[3], v[4]) end end end -- replace the location header hostname with mapped value if other than current host -- this is to map redirects from origin to related env hosts local mapValue = ngx.ctx["mapValue"] local cs = ngx.ctx["cs"] if ngx.header["Location"] ~= nil then local _, _, scheme, hostname, path = ngx.header["Location"]:find("^(.*)://([^/]*)(.*)") if ngx.var.host ~= hostname then ngx.header["Location"] = scheme .. "://" .. mapValue(hostname) .. cs(path) end end } } location /info { content_by_lua ' local info = require "info" info()'; } } }