server { listen 80; listen 443 ssl http2; server_name *.dev.iterget.com; # allow 127.0.0.1; ssl_certificate /usr/local/openresty/nginx/conf/ssl/web9.dev.iterget.com.pem; ssl_certificate_key /usr/local/openresty/nginx/conf/ssl/web9.dev.iterget.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; access_log access_dev.iterget.log; error_log error_dev.iterget.log; index index index.html; set_by_lua $my_staticdir ' local host = ngx.var.http_host local staticdir = string.gsub(host, ".dev.iterget.com", ""); return staticdir '; root /home/www/static/$my_staticdir; # error_page 404 index.html; location / { index index.html; add_header Server-Dir $my_staticdir; root /home/www/static/$my_staticdir; try_files $uri $uri/ /index.html = 404; add_header Cache-Control no-cache; } location ~^/admin/(admin-index|func-auth-config|dept|pipeline|position|tenant|corp|pipeline|client-position|permission|meun-config|comment-info|basic-file|index|admin-parameter|process-center|talent-scope).* { index index.html; add_header Server-Dir $my_staticdir; root /home/www/static/$my_staticdir; try_files $uri $uri/ /index.html = 404; add_header Cache-Control no-cache; } location /rank/ { index index.html; add_header Server-Dir $my_staticdir; root /home/www/static/$my_staticdir; try_files $uri $uri/ /index.html = 404; } location /_upstream_switch { default_type 'application/json; charset=utf-8'; content_by_lua_block { local remoteaddr = tostring(ngx.var.remote_addr); local ups = ngx.req.get_uri_args()["upstream"] if ups == nil then ngx.say("usage: curl /_switch_upstream?upstream=quake_server") return end local location = ngx.req.get_uri_args()["location"] if location == nil then location = "api" end local host = ngx.var.http_host local key = host.."/"..location local ups_src = ngx.shared._G:get(key) ngx.shared._G:set(key, ups) ngx.say("{\n\"ip\":\"",remoteaddr,"\",\n\"host\":\"",host, "\",\n\"form\":\"",ups_src,"\",\n\"to\":\"",ups,"\"\n}") ; } } location /_shared_mem { default_type 'application/json; charset=utf-8'; content_by_lua_block { local array = {} for index,value in ipairs(ngx.shared._G:get_keys(1000)) do local i=0 table.insert(array,"\""..value.."\":\""..tostring(ngx.shared._G:get(value)).."\"") end local str="{\n"..table.concat(array,"\n,").."\n}" ngx.say(str); } } location /_upstream_list { default_type 'application/json; charset=utf-8'; content_by_lua_block { local locations = {"api","statistics","transform"} local array = {} for index,value in ipairs(locations) do local i=0 while( i <13 ) do local k="web"..i..".dev.iterget.com/"..value local v=ngx.shared._G:get(k) if v == nil then v="null" else v="\""..v.."\"" end table.insert(array,"\""..k.."\":"..v) i=i+1 end end local str="{\n"..table.concat(array,"\n,").."\n}" ngx.say(str); } } location /transform/ { set_by_lua $my_upstream ' local serverId = ngx.req.get_uri_args()["_upstream"] if serverId == nil then serverId = ngx.req.get_headers()["Server-Upstream"] end if serverId == nil then serverId = ngx.shared._G:get(ngx.var.http_host.."/transform") end if serverId == nil then local host = ngx.var.http_host local webn = string.gsub(host, ".dev.iterget.com", ""); local n = string.gsub(webn,"web",""); serverId = "http://192.168.1.108:9103" end return serverId '; proxy_next_upstream off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Host $host; add_header Server-Upstream $my_upstream; proxy_pass $my_upstream; # 长连接配置 proxy_buffering off; proxy_read_timeout 7200s; proxy_http_version 1.1; #nginx默认是http1.0, 改为1.1 支持长连接, 和后端保持长连接,复用,防止出现文件句柄打开数量过多的错误 proxy_set_header Connection ""; # 去掉Connection的close字段 } location /common/sse/connect { set_by_lua $my_upstream ' local serverId = ngx.req.get_uri_args()["_upstream"] if serverId == nil then serverId = ngx.req.get_headers()["Server-Upstream"] end if serverId == nil then serverId = ngx.shared._G:get(ngx.var.http_host.."/api") end if serverId == nil then local host = ngx.var.http_host local webn = string.gsub(host, ".dev.iterget.com", ""); local n = string.gsub(webn,"web",""); serverId = "http://192.168.1.108:909"..n end return serverId '; proxy_next_upstream off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Host $host; add_header Server-Upstream $my_upstream; proxy_pass $my_upstream; # 长连接配置 proxy_buffering off; proxy_read_timeout 7200s; proxy_http_version 1.1; #nginx默认是http1.0, 改为1.1 支持长连接, 和后端保持长连接,复用,防止出现文件句柄打开数量过多的错误 proxy_set_header Connection ""; # 去掉Connection的close字段 } location ~^/(api|quakeadmin|hr|common|open).* { set_by_lua $my_upstream ' local serverId = ngx.req.get_uri_args()["_upstream"] if serverId == nil then serverId = ngx.req.get_headers()["Server-Upstream"] end if serverId == nil then serverId = ngx.shared._G:get(ngx.var.http_host.."/api") end if serverId == nil then local host = ngx.var.http_host local webn = string.gsub(host, ".dev.iterget.com", ""); local n = string.gsub(webn,"web",""); serverId = "http://192.168.1.108:909"..n end return serverId '; proxy_next_upstream off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Host $host; add_header Server-Upstream $my_upstream; proxy_pass $my_upstream; # 长连接配置 # proxy_buffering off; proxy_read_timeout 7200s; proxy_http_version 1.1; #nginx默认是http1.0, 改为1.1 支持长连接, 和后端保持长连接,复用,防止出现文件句柄打开数量过多的错误 proxy_set_header Connection ""; # 去掉Connection的close字段 } location /statistics/ { set_by_lua $my_upstream ' local serverId = ngx.req.get_uri_args()["_upstream"] if serverId == nil then serverId = ngx.req.get_headers()["Server-Upstream"] end if serverId == nil then serverId = ngx.shared._G:get(ngx.var.http_host.."/statistics") end if serverId == nil then local host = ngx.var.http_host local webn = string.gsub(host, ".dev.iterget.com", ""); local n = string.gsub(webn,"web",""); serverId = "http://192.168.1.108:908"..n end return serverId '; proxy_next_upstream off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Port $server_port; proxy_set_header Host $host; add_header Server-Upstream $my_upstream; proxy_pass $my_upstream; } }