worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { server { listen 8080; set $target ''; location / { access_by_lua ' local t = io.popen("/app/checkPort") local a = t:read("*all") if( string.gsub(a,"%D","") == "0" ) then ngx.var.target="http://127.0.0.1:5000" else ngx.var.target="http://127.0.0.1:2233" end '; proxy_pass $target; } } }