Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

socket error on nginx proxy #169

Closed
A1Gard opened this issue Jul 9, 2023 · 3 comments
Closed

socket error on nginx proxy #169

A1Gard opened this issue Jul 9, 2023 · 3 comments
Labels
question Further information is requested

Comments

@A1Gard
Copy link

A1Gard commented Jul 9, 2023

when I use nginx to proxy my app I have socket error

websocket.js:43 WebSocket connection to 'wss://myappurl/socket.io/?EIO=4&transport=websocket' failed:

my nginx ssl config:

location / {
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $host;
		proxy_pass http://localhost:2222/;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
	}

I have used upstream too for nginx:

upstream websocket {
        server 127.0.0.1:2222;
}

but not helped me. We have problem on nginx config or app can't receive socket request.

I need to mention:

nodejs version v18.16.1
port 2222 is open at all
I don't have any problem with socket when I used this ip:2222 and can see log like this: (but on proxy neither)

[2023-07-09 00:04:19.036] [server] [-] Connection transport 'websocket' +0ms
[2023-07-09 00:04:25.712] [server] [-] disconnected { reason: 'transport close' } +6s
[2023-07-09 00:22:38.426] [server] [-] connection accepted {
  host: '185.173.129.205',
  time: 'Sat Jul 08 2023 20:22:38 GMT-0400 (Eastern Daylight Time)'
} +18m

I can't use ngrok at all
six moths ago I do it well, now not.

@A1Gard
Copy link
Author

A1Gard commented Jul 9, 2023

I found the problem, this problem wasted my time about 8 hours, plz update the doc :

add proxy_hide_header to config:

location / {
        proxy_pass https://localhost:2222;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_hide_header "Nothing"; 
    }

Pardon me about my idea about bug

@miroslavpejic85 miroslavpejic85 added the question Further information is requested label Jul 10, 2023
@miroslavpejic85
Copy link
Owner

miroslavpejic85 commented Jul 10, 2023

Hello @A1Gard,

The configuration you provided appears to be mostly correct. However, there is a small issue with the line proxy_hide_header "Nothing";. The proxy_hide_header directive is used to remove specific headers from the response sent by the upstream server. However, in this case, you are specifying a header name of "Nothing," which is not a valid header.

If you intend to hide a specific header, you should replace "Nothing" with the actual header you want to hide. For example, if you wanted to hide the "X-Powered-By" header, you would use:

proxy_hide_header X-Powered-By;

If you don't need to hide any specific headers, you can simply remove the proxy_hide_header line from your configuration.

Other than that, the rest of the configuration looks fine. It sets up a reverse proxy to redirect requests received on the root location (/) to https://localhost:2222. It also sets the necessary headers for handling WebSocket connections.

I'm going to close this issue, please, for help and support, join with us on official forum
Here you can find many answers and ask questions, interact with the community ;)

Thank you!

@A1Gard
Copy link
Author

A1Gard commented Jul 11, 2023

Thanks bro @miroslavpejic85
I joined bro, I have to add this line for this problem:

https://forum.hestiacp.com/t/latest-update-broke-my-websockets/3600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants