Graphql web socket connection failed over production - javascript

I Have tried every possible Nginx config but it's showing connection failed every time.
config file:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
proxy_pass http://127.0.0.1:1337;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
}
location /graphql {
proxy_pass https://bakbakgraphql.com/graphql;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
Error:

Related

Websocket connection issue on django production server

I am facing an issue with the WebSocket protocol. I am using Django channels/daphne. Everything is working normally on the development local server. I think the issue is with NGINX settings. The error code is 1006
Here is the reverse proxy that I am using:
location ~* \.(js|css|jpg|png|jpeg|html)$
{
try_files $uri $uri/ /;
}
location /
{
proxy_pass http://127.0.0.1:8000;
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 REMOTE-HOST $remote_addr;
#Persistent connection related configuration
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
proxy_ignore_headers Set-Cookie Cache-Control expires;
add_header Cache-Control no-cache;
expires 12h;
}
location /ws/ {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
proxy_set_header X-Forwarded-Host $server_name;
}
#PROXY-END/

Websocket with Apollo Express, Nginx and docker-compose

I am trying to set up WebSockets in GCP with graphql subscriptions and Nginx but, it is not working as i am getting an issue with the Nginx config.
server {
listen 80;
root web-react/build;
index index.html;
location / {
try_files $uri /index.html;
}
location ^~/graphql {
proxy_pass http://localhost:4000/graphql;
}
location /websocket{
proxy_pass http://graphql;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
}

deploying Angular + Node Express with Nginx, return blank page

I'm trying to deploy my angular application on my EC2. I already have a Different app running on port 3000. now i'm trying to deploy my angular app on port 3030. but when i access it via the IP:3030 it works fine, but after configuring it with nginx it returns black page and with some 404 error on the Network tab.
server {
listen 443 ssl;
server_name <ABC.DOMAIN.COM>;
ssl_certificate /etc/letsencrypt/live/<ABC.DOMAIN.COM>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<ABC.DOMAIN.COM>/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
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 $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-Forwarded-Proto http;
proxy_set_header X-Nginx-Proxy true;
proxy_redirect off;
}
location /goalmate{
rewrite /goalmate/(.*)$ /$1 break;
proxy_pass http://localhost:3030/;
}
}
}
server {
listen 80;
server_name <ABC.DOMAIN.COM>;
return 301 https://$host$request_uri;
}
Error Showing in the Networktab
can someone help me.?
should'nt the requeston the networkTab show domain.com/goalmate/assets/ other than domain.com/assests

Nginx not asking for client cert when POST method with payload

I have configured nginx for ssl-client-authentication. It is working fine for GET and POST (with out payload). But when we use POST with body, client is not passing the certificate.
Either nginx is not asking for the cert
Or the client(javascript) itself is ignoring the cert i'm not sure
Nginx Configuration
upstream abc-abc.com {
ip_hash;
server 172.16.x.x:8987;
}
server {
listen 443 ssl;
client_max_body_size 100M;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate ssl/bundle.crt;
ssl_certificate_key ssl/abc.key;
ssl_verify_client optional;
ssl_client_certificate /certs/client_ca.cert;
# Use Server preference
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
server_name "~^abc-(?:[A-Za-z0-9]{0,21}[A-Za-z0-9])?-?abc.com";
proxy_buffering off;
error_log /proc/self/fd/2;
access_log /proc/self/fd/1;
server_tokens off;
location = /robots.txt {
return 200 "User-agent: *\nDisallow: /\n";
}
location / {
proxy_pass https://abc-abc.com;
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-Forwarded-Proto $scheme;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 36000s;
proxy_set_header X-SSL-Serial $ssl_client_serial;
proxy_set_header X-SSL-Verify $ssl_client_verify;
proxy_set_header X-SSL-SDN $ssl_client_s_dn;
proxy_set_header X-SSL-Cert $ssl_client_escaped_cert;
proxy_set_header X-SSL-Fingerprint $ssl_client_fingerprint;
proxy_set_header X-SSL-Start-Date $ssl_client_v_start;
proxy_set_header X-SSL-End-Date $ssl_client_v_end;
}
}
Please help, Thanks.

Making Socket.io path work with NGiNX proxy_pass

I would like to use NGiNX to proxy pass the following:
https://something.com/node.js/foo/bar/baz
into this:
https://something.com:3000/foo/bar/baz
I have successfully done it with the following NGiNX config:
location ~ /node.js/(.*) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "";
add_header Cache-Control "public";
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:3000/$1$is_args$args;
}
location / {
try_files $uri /index.php$is_args$args;
}
The problem is the following: when I instantiate socket.io with the default path, it serves socket.io.js here:
https://something.com/node.js/socket.io/socket.io.js
So far so good, but then this javascript tells the client to make requests here, which fail for obvious reasons:
https://something.com/socket.io/...
So then I try to instantiate socket.io with the path option like so:
io.listen(server, { path: '/node.js/socket.io'} );
But the problem is that now the socket.io.js file is hosted here:
https://something.com/node.js/node.js/socket.io/socket.io.js
Is there a way to tell socket.io.js where to host the file socket.io.js but still use the given path?
What is the normal solution to this proxy_pass stuff with socket.io??
Well different ways to solve your issue but I would use below one
location ~ /node.js/(.*) {
rewrite "^/node.js/node.js/(.*)$" /node.js/$1 last;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "";
add_header Cache-Control "public";
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:3000/$1$is_args$args;
}
location / {
try_files $uri /index.php$is_args$args;
}

Categories