#!/bin/bash

# https://docs.nginx.com/nginx/admin-guide/security-controls/securing-tcp-traffic-upstream/

echo "增加"

num=$(cat "/etc/nginx/nginx.conf" | grep -c "conf.d/stream")

if [[ $num -eq 0 ]]; then
    cat >>/etc/nginx/nginx.conf <<EOF
include /etc/nginx/conf.d/stream/*.conf;
EOF
fi

mkdir -p /etc/nginx/conf.d/stream/

echo "开始写入反向代理的配置"
cat >/etc/nginx/conf.d/stream/octopus-env-proxy.conf <<EOF
stream {

    # mysql
    server {
        listen 21306;
        proxy_pass 140.238.14.103:21306;
    }

    # nacos
    server {
            listen 21060;
            proxy_pass 140.238.14.103:21060;
        }
    # nacos
    server {
            listen 22060;
            proxy_pass 140.238.14.103:22060;
        }


    #rabbitmq
    server {
     listen 20672;
            proxy_pass 140.238.14.103:20672;
        }
    # dashboard
     server {
      listen 20678;
                proxy_pass 140.238.14.103:20678;
            }

    # redis
    server {
     listen 21370;
            proxy_pass 140.238.14.103:21370;
        }
}
EOF

echo "开始重启Nginx！"
systemctl restart nginx
