Websocket with Apollo Express, Nginx and docker-compose - javascript

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;
}
}

Related

Graphql web socket connection failed over production

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:

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

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 reverse proxy to node HTTPS

I've got an NGINX server running a reverse-proxy server to a node app.
Now I need to get it working with https but I keep getting 502: Bad Gateway error when trying to access the site at https
server {
listen 80;
server_name MYSERVERDOMAIN;
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;
}
}
server {
listen 443 ssl;
server_name MYSERVERDOMAIN;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
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;
}
}
Your setting looks correct, so I'm not quite sure about the issue. However, I'm using below setting for my production server with additional config for static assets folder and https auto-forward - which is the ultimate settings you may want for your production servers. Hope that it can help:
server {
listen 80;
server_name example.com;
rewrite ^/(.*) https://example.com/$1 permanent;
}
server {
server_name example.com;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /etc/ssl/certs/www.example.chained.cer;
ssl_certificate_key /etc/ssl/private/www.example.com_ssl_private_key.key;
root /var/www/example/public;
location / {
try_files $uri #proxy;
}
location #proxy {
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;
}
}

NodeJS cannot upload file cause upstream prematurely closed connection

When created a website with nodejs. In this website I have a page that can upload image to server. I tested this on my computer it's work fine. After I deploy it to server it's not working. I read the log. I got two from both access and error log at the same time.
This is an error.log
upstream prematurely closed connection while reading response header from upstream , client: xx.xx.xx.xx, server: example.com, request: "POST /admin/place/thumbnanil/upload HTTP/1.1", upstream: "http://127.0.0.1:3002/admin/place/thumbnanil/upload", host: "example.com", referrer: "https://example.com/admin/place/detail"
This is an access.log
POST /admin/place/thumbnanil/upload HTTP/1.1" 502 583 "https://example.com/admin/place/detail"
This is my nginx virtual host
upstream example {
server 127.0.0.1:3002;
keepalive 8;
}
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:3002;
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;
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 2048 8k;
}
}
I'm using ubuntu 14.04 on AWS EC2.
NodeJS v4.4.7
This is the url that I'm using for post : https://example.com/admin/place/thumbnanil/upload
Try 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 http://localhost:3002/;
proxy_read_timeout 90;
proxy_buffering off;
proxy_redirect http://localhost:3002/ https://example.com/;
}

Categories