ngrok error Failed to read valid http request: malformed HTTP request - linux

I'm using ngrok building a Secure tunnels to localhost server
On server side I run the command start ngrok
./bin/ngrokd -domain="tunnel.kmic168.com" -httpAddr=":8080"
Display
[07/12/17 17:37:16] [INFO] [registry] [tun] No affinity cache specified
[07/12/17 17:37:16] [INFO] [metrics] Reporting every 30 seconds
[07/12/17 17:37:16] [INFO] Listening for public http connections on [::]:8080
[07/12/17 17:37:16] [INFO] Listening for public https connections on [::]:443
[07/12/17 17:37:16] [INFO] Listening for control and proxy connections on [::]:4443
It seems fine. Then I run the command on client side
./ngrok -subdomain=rbp -config="ngrok.cfg" 80
and the
Tunnel Status: reconnecting .
Alway reconnecting. Then I checkd the server side display these error
[07/12/17 17:40:13] [INFO] [pub:7ac836d4] New connection from
119.130.171.143:25904 [07/12/17 17:40:13] [WARN] [pub:7ac836d4] Failed to read valid http request: malformed HTTP request
"\x16\x03\x01\x00\x9a\x01\x00\x00\x96\x03\x03;Qߓ\xccj\xb7nm\xa0\xe0\x86\x04\u007fH{W5\x10\xb1\xc4\xcc\xed\xe5\xbf\xc9\x00\xa1ĥbq\x00\x00\x1c\xc0/\xc0+\xc00\xc0,\xc0\x13\xc0\t\xc0\x14\xc0"
[07/12/17 17:40:13] [DEBG] [pub:7ac836d4] Closing [07/12/17 17:40:23]
[INFO] [metrics] Reporting:
{"bytesIn.count":0,"bytesOut.count":0,"connMeter.count":0,"connMeter.m1":0,"httpTunnelMeter.count":0,"linux":0,"osx":0,"other":0,"tcpTunnelMeter.count":0,"tunnelMeter.count":0,"tunnelMeter.m1":0,"windows":0}
Here is my cfg file content
server_addr: "tunnel.kmic168.com:8080"
trust_host_root_certs: false
Is there a solution to resolve this error? Thank you very much!

finally I found the solution
https://gist.github.com/lyoshenka/002b7fbd801d0fd21f2f
you have to use the port 4443

Related

Socket.io giving a connection error when connecting via a reverse proxy even though the connection works

I'm hosting a website on my raspberry pi using apache2 as a front end proxy for the node.js back end on port 3000. I'm using socket.io to communicate between the raspberry pi and the website. The reverse proxy in the app.js file is here:
httpProxy.createProxyServer({
target: "http://localhost:3000",
ws: true,
}).listen(8080);
Port 8080 is used because port 80 is already being used by the apache server.
When I connect on localhost directly to the node.js app everything works properly, but when I connect via the public ip, the connection works but I get the error message:
WebSocket connection to 'ws://publicip/socket.io/?EIO=4&transport=websocket&sid=-pP0gAI8TJHz780gAAAE' failed:
doOpen # websocket.js:54
When accessing the website, the following error messages appear in the apache error logs:
[Sat Jul 16 23:27:17.005680 2022] [proxy_http:error] [pid 20424] [client publicip:55245] AH01114: HTTP: failed to make connection to backend: 127.0.0.1, referer: http://publicip/
[Sat Jul 16 23:27:17.759148 2022] [proxy:error] [pid 11996] (111)Connection refused: AH00957: http: attempt to connect to 127.0.0.1:3000 (127.0.0.1:3000) failed
The connection works as I have some code that sends a signal to the raspberry pi via socket.emit on a button press and this is received in the raspberry pi, so this isn't a huge issue but I'm wondering if there is a better way to do the reverse proxy as this error message is annoying.

Upgrading WebSocket for the first time takes a long time with express + http-proxy-middleware

I have a Graphql server with subscriptions enabled, when accessed directly from my client it works great. Now what I need to do is reroute the connection through my backend (an express server).
I have the following configuration on my server:
app.use(
"/graphql",
createProxyMiddleware({
target: `http://${GQL_URL}`,
changeOrigin: true,
ws: true,
})
);
This eventually works, however, the first connection when the server starts-up, which I can see in my console the message [HPM] Upgrading to WebSocket takes over five minute to complete.
By the time it manages to upgrade the connection, the client has already disconnected and retried multiple times and I get "instantly" all the stacked pending retries:
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
[server] [HPM] Client disconnected
[server] [HPM] Upgrading to WebSocket
After that, the connections to the server work properly.
In principle this is not a major problem, as when I deploy, the application will not work for a few minutes and then start working, is not ideal but not all bad.
However, the major problem is when I am developing. Whenever I make any change to the servers code and it reloads I have to wait those few minutes to properly checkout if my application is working.
How can I fix this issue? Am I missing something?

sockjs-node net::ERR_CONNECTION_REFUSED [duplicate]

This question already has an answer here:
GET: ERR_SSL_PROTOCOL_ERROR nginx + vue.js
(1 answer)
Closed 3 years ago.
I created a brand new tiny webapp with vue cli, so without adding anything, apart from what the empty vue-cli scaffolding brings:
(base) marco#pc:~/vueMatters/testproject$ npm run serve
> testproject#0.1.0 serve /home/marco/vueMatters/testproject
> vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin
DONE Compiled successfully in 1409ms 8:14:46 PM
App running at:
- Local: localhost:8080
- Network: 192.168.1.7:8080
Note that the development build is not optimized.
To create a production build, run npm run build.
And got this error message :
GET https://localhost/sockjs-node/info?t=1580228998416 net::ERR_CONNECTION_REFUSED
node --version
v12.10.0
npm -v
6.13.6
webpack-cli#3.3.10
Ubuntu 18.04.03 Server Edition
last lines of /var/log/nginx/error.log :
2020/01/28 18:10:57 [error] 980#980: *34 connect() failed (111:
Connection refused) while connecting to upstream, client:
66.249.79.119, server: ggc.world, request: "GET /robots.txt HTTP/1.1",
upstream: "http://127.0.0.1:8080/robots.txt", host: "ggc.world"
2020/01/28 18:11:37 [error] 980#980: *36 connect() failed (111:
Connection refused) while connecting to upstream, client: 66.249.79.70,
server: ggc.world, request: "GET /robots.txt HTTP/1.1", upstream:
"http://127.0.0.1:8080/robots.txt", host: "www.ggc.world"
How to solve the problem?
You need to specify SSL Certificates in your socket connections.
Here is the reference.
var options = {
key: fs.readFileSync('./file.pem'),
cert: fs.readFileSync('./file.crt')
};
var server = https.createServer(options, app);
var io = require('socket.io')(server);

AWS elastic Beanstalk / nginx : connect() failed (111: Connection refused

I got this message
connect() failed (111: Connection refused
Here is my log:
-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2018/10/21 06:16:33 [error] 4282#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.4.119, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com"
2018/10/21 06:16:33 [error] 4282#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.4.119, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com", referrer: "http://hackingdeal-env.qnyexn72ga.ap-northeast-2.elasticbeanstalk.com/"
I am using nodejs/express Elastic Beanstalk env.
I have one nginx related file in
.ebextensions/nginx/conf.d/proxy.conf
Upper file contains:
client_max_body_size 50M;
Whenever I try to get my webpage I got 502 bad gateway.
What's wrong with my app?
Just recording my incident here just in case it helps someone or my future self. I had a Django application that had SECURE_SSL_REDIRECT set to True. Since I had no load balancers configured to handle HTTPS traffic I was getting a timeout. Setting it to False fixed the issue. Couple of days wasted on that one.
111 connection refused likely means your app isn't running on the server/port combination. Also check that the security group for your app instance (or load balancer) has an inbound rule set to allow traffic from the nginx instance
I was dealing with this error on my NodeJS application (NEXTJS). Posting this here just in case is useful for someone.
My error was thet the deploy command failed at the build step (next build), which means the Node server never restarted. For that reason nginx could not find the server. You can find this kind of errors in the web.stdout.log
I tested my build command locally, fixed the errors and it worked!

HAProxy 1.6 configuration Node.js ssh server child process

I am running a Node.js SSH server that spawns a child process to exec code (using require('child_process').spawn) after successful authentication.
The client server connections works fine on port 22 and connection is kept alive successfully through spawned process.
I am trying to setup up now with HAProxy 1.6, to forward port 22 to a non-privileged port on which the SSH server is listening.
However, when the child process is spawned the server either errors Error: write EPIPE or Error: read ECONNRESET.
This suggests to me there is an issue with prematurely closed stream or connection between the client -> HAProxy -> server?
I am looking at websocket configurations and ssh configurations for HAProxy and various keep alive options. However I cannot get the connection to work.
My configuration:
global
daemon
maxconn 10000
log 127.0.0.1 local0
defaults
log global
option tcplog
option logasap
timeout connect 500s
timeout client 5000s
timeout server 2h
timeout server-fin 5000s
timeout client-fin 5000s
timeout tunnel 1h
option tcpka
frontend sshd
bind *:22
default_backend ssh
timeout client 2h
backend ssh
mode tcp
server ssh2server 127.0.0.1:5000 check port 5000
Any pointers or help would be awesome. Thanks in advance.
EDIT
Runing haproxy in debug mode I have
00000000:sshd.accept(0004)=0005 from [my ip]
00000000:ssh.srvcls[0005:0006]
00000000:ssh.clicls[0005:0006]
00000000:ssh.closed[0005:0006].
On the tcplog
Oct 15 15:15:38 localhost haproxy[16036]: 128.277.13.23:51146 [15/Oct/2016:15:15:38.804] sshd ssh/ssh2server 1/0/+0 +0 -- 1/1/1/1/0 0/0

Resources