Node.JS/socket.io and safari - javascript

I have a node.js software that use socket.io 1.3.0 lib for communication between client and server.
In my architecture the server is behind a proxy nginx.
I test the software with all last browser version.
Everything works except when i use Safari (last version).
I read that Safari uses an earlier version of the protocol WebSocket (hixie-76).
My question is: there is a way to change in socket.io the protocol version when i use Safari browser?
This is my nginx (1.7.12) configuration:
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
proxy_pass http://internalhost:8080/;
}
Thanks in advance.

Related

Node Socket Server Errror on nginx server

I have created a socket for my messaging app which is working fine on the local server. Connection and Listeners are working properly.
But When I updated that on the server, Then not able to establish the connection.
I am using pm2 for running ports on nginx server.
This is how my configuration looks like here -
/etc/nginx/sites-available/default
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /socket {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
PS: MY js code seems fine as that is working fine on local server so not adding here. I am assuming it's a problem from here with the configuration

create-react-app code changes behind nginx reverse proxy not reloading in browser

Ive installed a new CRA template and Im unable to see file changes reflect in the browser. Im reverse proxying React app through nginx using unmodfied CRA installation (unmodified apart from setting .env VAR PORT corresponding to standard nginx websocket proxy config). Still I see persistent browser error:
webpackHotDevClient.js:60 WebSocket connection to 'wss://react.syntapse.co.uk/sockjs-node' failed: Error during WebSocket handshake: Unexpected response code: 301
.env file
PORT=3121
nginx configuration
server {
listen 80;
server_name react.syntapse.co.uk;
location /sockjs-node/ {
proxy_pass http://0.0.0.0:3121/sockjs-node/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
proxy_pass http://0.0.0.0:3121/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I haven;t taken any specific steps to enable HMR or any form of hot reloading just expecting code changes to update in the browser. I'm trying out different platforms and ive got near identical nginx config for default angular and vue apps which just work with HMR out the box so I guess React config needs tweaking to work with through proxy but the documentation is a bit sparse.
Any help or insights into using React with nginx reverse proxy are much appreciated.
Thanks
Answer in plain sight the whole time! drop the end slash.
location /sockjs-node {
proxy_pass http://0.0.0.0:3121/sockjs-node;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

Websocket connection for nginx and parity?

I am running a dAPP on a cloud server and using nginx and parity client with wesocket enabled on it.
I installed a certbot certificate for the https domain.
Now i am having problem that while accessing my website using https it gives an error on chrome that..
web3-providers.umd.js:1269 Mixed Content: The page at 'https://www.
chain.com/' was loaded over HTTPS, but attempted to connect to the
insecure WebSocket endpoint 'ws://40.138.47.154:7546/'. This request has
been blocked; this endpoint must be available over WSS.
then i added the reverse proxy on nginx config file as
location / {
# switch off logging
access_log off;
proxy_pass http://localhost:7556; #Port for parity websocket
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
and then it is giving an error of
"WebSocket interface is active. Open WS connection to access RPC."
What is the problem here and what should i try?
Thanks
The https won't allow loading insecure content on the page.
One possible solution is to use the SSL/TLS terminator between the application server and the client.
From the official Nginx docs, the relevant part of the config file could be like this:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server localhost:7546;
}
server {
listen 443;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
}
ssl on;
# specify cert and key
}
Inside the dApp change 'ws://40.138.47.154:7546/' to wss://40.138.47.154.

How to get visitor's IP if my node app is behind a nginx reverse proxy?

I understand it is possible to get a visitors IP using code similar to the following:
var ip = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
However when I use this code in my node app (which sits behind a nginx reverse proxy on the same server), I just get the IP 127.0.0.1.
This is my nginx location:
location /myapp {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
How can I overcome this problem?
Thanks for your help.

nginx and proxy_redirect partially working?

I'm having a lot of trouble trying to reverse proxy a .NET application (specifically sharepoint)
The sharepoint application lives at 192.168.5.8
nginx lives at 192.168.2.115 and has another IP at 192.168.5.200
I am using nginx to proxy several applications using the url to distinguish each app
My problem is with "/vmlab/" and not "/rdp/"
sites-available/default:
location ^~ /vmlab {
proxy_pass http://192.168.5.8/;
proxy_redirect http://192.168.2.115/ http://192.168.2.115/vmlab/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
proxy_set_header Authorization "Basic {base64 string}";
}
location /rdp/ {
proxy_pass http://192.168.2.115:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffering off;
#proxy_buffers 32 4k;
}
So when I hit http://192.168.2.115/vmlab the back-end request goes to http://192.168.5.8 which is great, except that the web application automatically sends a location redirect Location: http://192.168.2.115/default.aspx, therefore I added the proxy_redirect which seems to partially work.
My problem is that even though some requests like http://192.168.2.115/vmlab/default.aspx are being now being proxied to http://192.168.5.8/default.aspx (but show as http://192.168.2.115/vmlab/default.aspx) with the proxy_redirect, others that show up in the client browser (such as javascripts and stylesheets) still show like the following http://192.168.2.115/_layouts/... which is missing the required "/vmlab/" URI and therefore don't exist.
Is this a problem with my configuration and the proxy, or by design with absolute paths in stylesheets and javascript code?

Categories