From d4a77b07d9c1130b8ea483b4b948bd7e667d73ff Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Thu, 29 Oct 2020 15:47:19 +0200 Subject: [PATCH] Minor updates --- Dockerfile | 3 ++- configs/nginx | 39 +++++++++++++++++++++++++++++++++++++++ lib/ClientManager.js | 7 ++++--- package.json | 6 ++++-- 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 configs/nginx diff --git a/Dockerfile b/Dockerfile index ddda30b..092896d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,4 +10,5 @@ RUN yarn install --production && yarn cache clean COPY . /app ENV NODE_ENV production -ENTRYPOINT ["node", "-r", "esm", "./bin/server"] +ENV DEBUG * +ENTRYPOINT ["node", "-r", "esm", "./bin/server", "--secure", "--max-sockets", "20"] diff --git a/configs/nginx b/configs/nginx new file mode 100644 index 0000000..1a128da --- /dev/null +++ b/configs/nginx @@ -0,0 +1,39 @@ +server { + listen 80; + listen [::]:80; + server_name a8c-localtunnel.cyou *.a8c-localtunnel.cyou; + return 301 https://$host$request_uri; +} +server { + listen 443 ssl; + server_name a8c-localtunnel.cyou *.a8c-localtunnel.cyou; + ssl_certificate /etc/letsencrypt/live/a8c-localtunnel.cyou/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/a8c-localtunnel.cyou/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; + + location / { + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Host $http_host; + proxy_set_header Connection 'upgrade'; + # proxy_set_header Connection ""; + + proxy_set_header X-Forwarded-Proto https; + + proxy_cache_bypass $http_upgrade; + proxy_http_version 1.1; + proxy_pass http://127.0.0.1:1234; + + # Fix for "146656 upstream sent too big header while reading response header from upstream" + # https://ma.ttias.be/nginx-proxy-upstream-sent-big-header-reading-response-header-upstream + proxy_buffer_size 128k; + proxy_buffers 4 256k; + proxy_busy_buffers_size 256k; + + # Ugly fix for Connection timed out error + proxy_send_timeout 150; + proxy_read_timeout 150; + + } +} diff --git a/lib/ClientManager.js b/lib/ClientManager.js index e1a7838..9a2071d 100644 --- a/lib/ClientManager.js +++ b/lib/ClientManager.js @@ -37,10 +37,11 @@ class ClientManager { id = hri.random(); } - const maxSockets = this.opt.max_tcp_sockets; + const maxTcpSockets = this.opt.max_tcp_sockets; const agent = new TunnelAgent({ clientId: id, - maxSockets: 10, + maxTcpSockets, + }); const client = new Client({ @@ -63,7 +64,7 @@ class ClientManager { return { id: id, port: info.port, - max_conn_count: maxSockets, + max_conn_count: maxTcpSockets, }; } catch (err) { diff --git a/package.json b/package.json index 0693b8d..f00473f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,9 @@ }, "scripts": { "test": "mocha --check-leaks --require esm './**/*.test.js'", - "start": "./bin/server", - "dev": "node-dev bin/server --port 3000" + "start": "node -r esm bin/server --port 1234 --max-sockets 30", + "start-docker": "docker run -d --restart always --name localtunnel --net host defunctzombie/localtunnel-server:latest --port 1234", + "dev": "node-dev bin/server --port 3000", + "stuff": "docker build --tag a8c-lt:1.0 . && docker run -d --restart always --name lt --net host a8c-lt:1.0 --port 1234" } }