intermediate hops in nginx reverse proxy - reactjs

I am new to nginx and doing full stack development for the first time. Could you please help me understand the below logic
Lets say we are building a chatting app. We have 3 servers (EC2 instances)
server_nginx - ec2 running a nginx server working as reverse proxy
server_react - ec2 running a react project through nginx as web server
server_spring - ec2 running a spring boot project through nginx as web server
My reverse proxy is running through SSL/https. Initially everything was happening on same machine, so I made my spring boot service also ssl because I could not initiate a http connection over https. Now the I started separating out the instance as mentioned above (3 ec2 instances). I was expecting that the connection to my backend would fail. Reason :
user connects to reverse proxy through https domain (lets say mydomain.com).
The request comes to server_nginx(mydomain.com).
From here this proxies this to server_react (which is running on simple http). This is the server where my react code is hosted
This react code tries to initiate a web socket connection to server_spring where I have enabled the CORS for mydomain.com. So I was expecting that the connection would fail here as this is a different IP now. But surprisingly all the apis are getting the response as if I am hitting it from mydomain.com
So can anyone please help me understand why is the behaviour like this
Thanks.

Related

Forcing JS fetch to use non-https

I have an in-development ReactJS application that I run locally from my computer (on localhost). I have also set up local certs so that the application runs on HTTPS (https://localhost).
I also have a backend application located at an HTTP endpoint hosted in the cloud. Of course, the backend application will eventually be located at an HTTPS endpoint eventually, but that process hasn't been started yet.
I am trying to hit that HTTP endpoint from my local HTTPS ReactJS application by using fetch. However, something is upgrading the connection from HTTP to HTTPS automatically.
The only relevant information I have found on this is this post. I have tried the accepted answer (setting the referrerPolicy to unsafe-url) but that did not work for me.
Any other suggestions?

SignalR with Angular front-end works on localhost, but doesn't work remotely

I have two Azure Web App Services: front-end (written on Angular) and back-end (written in C# with SignalR). Either of them is placed on its own server, and I am trying to make front-end connect to back-end. Previously everything worked locally when I ran it on localhost, with http, but when I try to do the exact same thing on Azure (I replaced localhost with azure website domains), I get this error in Chrome:
I see that https is replaced by 'wss', which I guess is not fine for SignalR (because it's supposed to fall back to https/https if wss/ws is unavailable, as one of the commenters stated). So apparently my front-end can't see my backend.
What I've tried so far:
Changing protocols to http, the way it was with localhost
Setting backend to listening to 0.0.0.0:5000
Turning on Web Sockets in Azure settings (on both client and server)
What is my problem, and how do I connect my client side to the server side? Thanks.
You should not use port 5000 on App Service. Configure your app so that it only uses the default ports when deployed (effectively port 80 and 443). WSS/SignalR works fine over these default ports.
You can also see the list of exposed ports.

React and spring boot api at one VPS

I’m trying to configure my react and spring boot rest api at my vps server and I met we problems. Firstly, when I run my front api (react) and I’m trying to call my backend (spring boot) I must use https://example.com:8080 address.
When I try to use my vps ip with port, my https is turns off… its write that my https is dangerous. Next, when im trying to call https://localhost:8080 i have error that i cannot connect to this address.
So:
call to https://example.com:8080 work
Https://ipaddress:8080 not working (lost my ssl certificate)
Https://localhost:8080 not working (connection refused)
My backend is work on port 8080. Is running, when im trying to call localhost by curl in command line its working, but on browser not… how to call api? Is example.com:8080 correctly connection? I think that can be some lags because of ssl handshake…
I will add that when im running front and backend locally, localhost is working…
What is the best practice to call backend when im running front and backend on one vps?

Adding domain name in digitalocean droplet

I have recently bought a domain from Godaddy. I have done the necessary setups to connect it with digitalocean droplet. I can access the website using the domain. The domain is by default using HTTPS. But inside the web app, I have made HTTP requests(for login, sign up). These network requests aren't being made if I access the website using the domain name. But if I access it by using the IP address of the droplet, those network requests were working. I guess the problem is with the domain. There is no SSL certificate present in the droplet. I am using the Nginx server in the droplet. I have used React to build the website.
I am new to web hosting. Can anybody tell me what's wrong here and how to fix this?
If I understood your question correctly, i think the issue might be in nginx config.
SSL requests that are coming to your droplet over HTTPS should be decrypted somewhere... You can either do it in nginx by using a certificate and modifying your nginx config accordingly, or you can use a digital ocean load balancer in front of your server and configure that load balancer to terminate SSL (you can get a digital ocean managed cert)... In both of these cases, your app will receive un-encrypted traffic.
These links might help:
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing-with-ssl-termination
https://www.digitalocean.com/docs/networking/load-balancers/how-to/ssl-termination/

net::ERR_CONNECTION_TIMED_OUT from angular to nodejs in k8s

I am trying to make request to nodejs backend from containerized AngularJS frontend to nodejs.
Both are deployed in AWS using Kubernetes(KOPS). And I created service to access both.
For frontend type is LoadBalancer in k8s services and for backend, its ClusterIP. I can access frontend from browser using URL of the load balancer which "kubectl get services" gives me. But when frontend tries to make request to backend I am getting following error:
net::ERR_CONNECTION_TIMED_OUT or net::ERR_NAME_NOT_RESOLVED.
I checked using telnet etc, and app is running and can be accessed. Direct access to hostname works but doesn't work from AngularJS/NodeJS.
Your post was light on specifics, but if I understand correctly:
1. ELB -> Service -> Pod("http-server-serving-Angular")
2. ClusterIP -> Service -> Pod("nodejs")
Is that correct? because if so:
and for backend, its ClusterIP
Cluster IP addresses are, as their name suggests, only available within the cluster. You will want the backend Service to be of type LoadBalancer, also, so traffic that is not in the cluster can reach the nodejs app.
I'm cheating you with that answer just a tiny bit, because you can absolutely provision an Ingress controller and then leave the other Services as ClusterIP, but I would bet that's not the typical setup.
i think i found the problem. Here is the possible cause. I am using express.js for frontend which is hosted in nodejs. We wrote service which makes connection to backend host. This is not being served through http server and this is making connection being made from client's browser. I tried adding public ip to backend and it was working as expected. So possible fix it serve express/angular from nodejs web server.
This is not kubernetes question. I apologize for adding misleading tag.
Thanks for all the replies guys!
So this problem was wrong rule in nginx controller. My ingress has typo which was causing frontend to not recognize url. This issue is resolved.

Resources