diff --git a/conf/nginx.conf b/conf/nginx.conf index f374719..1b17a2b 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -6,15 +6,20 @@ events { http { server { listen 8080; +set $target ''; location / { access_by_lua ' + local t = io.popen("/app/checkPort") + local a = t:read("*all") - local t = io.popen("checkPort") - local a = t:read("*all") - - ngx.say("

当前进程"..a.."

") - + 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; } } } \ No newline at end of file diff --git a/shell/checkPort b/shell/checkPort index abe9e22..05acad9 100644 --- a/shell/checkPort +++ b/shell/checkPort @@ -1,8 +1,8 @@ #!/bin/sh # 检查客户端和服务端端口是否存在 #存在返回0否则返回1 -source riskenv -if [[ `findPortPid $PORT|wc -l` -eq 1 && `findPortPid $serverPort|wc -l` -eq 1 ]] +source /app/riskenv +if [[ `/app/findPortPid $PORT|wc -l` -eq 1 && `/app/findPortPid $serverPort|wc -l` -eq 1 ]] then echo 0 else diff --git a/shell/findPortPid b/shell/findPortPid index a457137..4a40edd 100644 --- a/shell/findPortPid +++ b/shell/findPortPid @@ -1,6 +1,7 @@ #!/bin/sh # 查找端口pid -if [[ $# == 1 && `netstat -antp|grep $1|wc -l` -eq 1 ]] +port=`netstat -antpl|grep $1|awk '{printf $7}'|cut -d/ -f1` +if [[ $# == 1 && `echo $port|wc -l` -eq 1 ]] then - netstat -anp|grep $1|awk '{printf $7}'|cut -d/ -f1 + echo $port fi