Control Web Panel
WebPanel => Apache => Nginx => Topic started by: rfm on July 30, 2020, 02:41:35 PM
-
I'm trying to start a websocket, but in https it doesn't work.
WebSocket connection to 'wss://myurl.com.br:8585/' failed: WebSocket opening handshake timed out
I've been researching and I saw that you have to make a configuration in ngnix, but I didn't find where to make this configuration in the domain,
https://www.nginx.com/blog/websocket-nginx/
-
What exactly do you trying to do and for what?
-
What exactly do you trying to do and for what?
I have the same problem.
So, my CWP panel was configured as:
Nginx & Apache
Additional Options: php-cgi/suphp, nginx/php-fpm, apache/php-fpm, proxy
HTTP: Nginx (80) --> Apache (8181)
HTTPS: Nginx (443) --> Apache (8181)
I want to run a WebSocket application that using localhost address 0.0.0.0:8282 for communication
So I have put a cron job to run my chatserver websocket app using a command:
php index.php chatserver server
Now I can see that the chatserver is run:
Running server on host 0.0.0.0:8282
But in the browser client side I can see an error like that:
WebSocket connection to 'wss://***.***:8282/?***' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
socket.js?v=***:** WebSocket connection to 'wss://***.***:8282/?***' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Looks like nginx doesn't let to pass the socket connection on the port 8282.
Could you please to help me to change the nginx configuration file of the specific domain that works over SSL to successfully establish websocket connection to the port 8282 and connected to my localhost chatserver.
I will appreciate for any help.
-
socket.io and wss will work fine with nginx just you need to create complete vhost template by your own.
-
Could you give me an example, please? I already spent the last 3 hours and still didn't find a solution. I mean example of template in case if the chat app gonna work from the wss://***.com:8282
How to make a port forwarding through ngnix to apache?
-
templates are stored here
http://wiki.centos-webpanel.com/webservers-vhost-templates
check with your script provider for proper documentation config for nginx towards your script
-
There is no script provider, I am writing a chat application and it works without any problem on my xampp, but I am getting stucked with Nginx port forwarder through SSL connection.
Briefly I am running a chatserver on my server (using boot cron task) under the name of the domainuser.
php index.php chatserver server
After running I am getting a message:
Running server on host 0.0.0.0:8282
When I am opening a browser I am getting errors like that:
app.js?v=1222333591:101 WebSocket connection to 'wss://***.***:8282/?access_token=1)%28?%2A' failed: WebSocket opening handshake timed out
So, if I understood correctly I need to tell to nginx that all requests to ****.com:8282 should be forwarded directly to localhost 0.0.0.0:8282 ???
-
did ytou opened the port 8282 in firewall ?
-
Yes, it is opened. Even when the firewall is switched off it doesn't work...
-
I found some useful information, but still didn't figure out how to add it considering CWP nginx existing configuration:
WebSocket proxying
http://nginx.org/en/docs/http/websocket.html (http://nginx.org/en/docs/http/websocket.html)
NGINX to reverse proxy websockets AND enable SSL (wss://)?
https://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss (https://stackoverflow.com/questions/12102110/nginx-to-reverse-proxy-websockets-and-enable-ssl-wss)
-
as i mentioned above you need to create template, as this tasks are not free.
-
Well, I think I am not the first one who is asking about Nginx + SSL + Websockets here in the forum. But so far all of those subjects without clean answer or without an answer at all. ¯\_(ツ)_/¯
I think that should be integrated into the CWP. I mean the possibility to add port forwarding. Anyway could you please give me a template example of the port forwarding through the templates?
I have tried to add at the end of the /etc/nginx/conf.d/vhosts/holistic.chat.ssl.conf
That description:
server {
server_name ***.***;
location / {
proxy_pass http://0.0.0.0:8282;
}
listen [::]:443 ssl;
listen 443 ssl;
ssl_certificate /etc/pki/tls/certs/***.***.bundle;
ssl_certificate_key /etc/pki/tls/private/***.***.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}
But it doesn't work.
-
Hello. I've found a way to redirect the server's websocket port to port 80 (or wss to 443).
On the vhosts conf file (WebServers Conf Editor > /etc/nginx/conf.d/vhosts/ tab), you should locate the location / { ... } part.
Replace the entire location / { ... } part with this:
location / {
proxy_set_header HOST $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_request_headers on;
proxy_pass http://YOUR_SERVER_IP:WEBSOCKET_PORT;
proxy_http_version 1.0;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
You should change only YOUR_SERVER_IP and WEBSOCKET_PORT part with the respective information. Leave the rest as it is. If you are editing the SSL conf file, instead of http you should use https.
It is working for me. I just wish someone directed me as how to create a template from this, to be able to use the CWP ui to set this config instead of by hand.