NodeJs / React wan't refresh files over https - node.js

I have a boring problem that I can't solve..
I tried in all ways but I don't understand why if I call the application through the IP:3000 it loads updated files, but if I try to call it trough https://domainname.ext it doesn't want to serve new files.
I tried to delete node_modules and rebuild it (npm install); to run "npm run eject" and rebuild the app; pm2 kill and restart; reboot the server but nothing...
The App is configured to run with Nginx as reverse proxy over https.

Classically one of the following solutions:
Browser cache ("external" Domains are cached, IPs not). Try a different Browser
Actually 2 apps running. Try to kill the process and see if it really goes down
Nginx caching?

Finally 😌
in my server block of nginx configuration i just changed from localhost to IP addr
location / {
proxy_pass http://IP.ADDR: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;
}

Related

Node JS hosting using Nginx Reverse proxy gives 404 error

I want to host a Nodejs API server to my digitalocean server where a WordPress application is already running using Nginx and PHP fpm
I followed the below link to set up the WordPress application and it's working fine now.
https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one-ubuntu-18-04-server
I wanted to set up Nodejs application inside the same server for demo purposes and I followed the digitalocean guide for setting up node js with a different config file and subdomain.
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04
My Nginx config for node application looks like this
server {
server_name sub.domain.com
location / {
proxy_pass http://localhost:6969;
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 have allowed port 6969 using ufw allow 6969.
I am able to access the Nodejs application using sub.domain.com:6969 but sub.domain.com gives me a 404 error. (404 Not Found nginx/1.18.0 (Ubuntu))
I want to access Nodejs application directly without a port number. I have checked Nginx logs and there are no errors, and configures is gives success in nginx -t
Please give me some suggestions to debug and fix this issue. I don't have much knowledge in Nginx configuration. I was just following tutorials from Digitalocean to configure the WordPress and node application.
Thanks in Advance
You are missing the port
server {
server_name sub.domain.com;
listen: 80;
location / {
proxy_pass http://localhost:6969;
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;
}

reverse proxy using sails 1, nginx, and node is very version dependent, how to fix?

I would like to have a more stable deployment of a sails 1 app on an AWS ubuntu server using nginx as reverse proxy.
Goal:
To have a non-version-dependent deployment of our app.
In particular:
We have an app on an AWS server.
App details include:
mobile focused
websockets enabled
reverse proxy with nginx
app persisting with pm2
Deployment details include
AWS ubuntu 18.04 LTS
mysql 8.x database
sails 1.2.4
nginx 1.14.0
node 8.4.0
The issue:
I was only able to get the reverse proxy working with the above versions of sails, nginx, and node. Any other combination resulted in a 403 error from the app server. Postman GET requests to the server when the app is served directly return a "sails.sid" cookie. However, when the app is served through any other reverse proxy software combination, no "sails.sid" cookie comes back in the GET header. I got the same no cookie GET request with apache2 reverse proxy.
When I hit the app directly (not through the reverse proxy) the cookies returned fine.
What I have tried
different versions of node, sails1, nginx, apache2
node versions > 10.22.0 cause the error
there is a known deprecation in node > 10.22.0 of the command
link to node deprecation
The http module OutgoingMessage.prototype._headers and OutgoingMessage.prototype._headerNames properties are deprecated.
This seems to break the nginx reverse proxy handling of headers from the sails app.
I have not seen a fix in nginx, and in particular nginx version 1.16.0 will break the headers.
other things I have tried
ownership and permissions (chmod, chown) are ok
apache2 reverse proxy: same problem as with nginx 1.16.0: no headers. I.E. the reverse proxy works, but the app returns a 403 code through the apache2 reverse proxy.
various permutations of versioning: sails, nginx, node
things I might try
Somewehere in the node-modules of sails, there may lurk header code depending on this old syntax. This could possibly be patched with a replace new-for-old on the appropriate statements. Just a thought.
What I would like:
Show me how to get this app working, i.e. get all the headers back from a vanilla Postman GET request, in a way that does not depend on these specific versions of sails, nginx, and node.
If I am missing something glaringly obvious, even better.
I am using a similar setup with node 11.15.0 and it works.
What is your nginx configuration?
Here is the server block code I tried to put in the comments. Remeber that you have to symlink it to the /etc/nginx/sites-enabled folder as well. This works for straight HTTP requests. Note that your app will only see the client "127.0.0.1". If you want to get the IP addresses from your clients out in the wild, you need to get them from the nginx reverse proxy server itself.
server {
listen 80;
server_name yourDomain.com ;
location / {
proxy_pass "http://127.0.0.1:1337";
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Port $server_port;
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_pass_request_headers on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /socket.io/ {
proxy_pass "http://127.0.0.1:1337/socket.io/";
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header Port $server_port;
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_pass_request_headers on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}

Cant deploy correctly Vuejs app from git in Jelastic

its the first time i use Jelastic and i need to deploy a vuejs app from git.
I've make a Nodejs env and deploy my vuejs app. Then, i run:
cd ROOT
npm install
npm run build
And i get an successfully message: Build complete. The dist directory is ready to be deployed.
So, what i usually do next in localhost is something like this:
cd dist
npm http-server
But in Jelastic i don't really know whats next after the build. I've try to go into http://node-env.route/dist but i get a 502 error page (The opened link forwards to the environment where the application server is down or is not picked up yet.)
Hope you can help me, thank you!
In order to run your application I suggest you to install pm2 on your server and run this command:
pm2 start npm --name "your-app-alias" -- start
After re-build you need to restart:
pm2 restart your-app-alias
Maybe after that you need a reverse proxy with NGINX to link your nodejs env to your localhost. Something like that:
server {
listen 80; # the port nginx is listening on
server_name YOUR-JELASTIC-ENV-URL; # setup your domain here
location / {
expires $expires;
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-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://127.0.0.1:3000; # set the adress of the Node.js instance here
}
}

Can you use `php artisan serve` with nginx like with nodejs?

The question above is for pure education, not for use in real world.
When reading on how to deploy a nodejs app on a VPS, I have found out, that nginx is forwarding all requests to a localhost port, which is served by node a nodejs app.
here is a nodejs config in digitalocean tutorial:
location / {
proxy_pass http://localhost: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;
}
I was wondering is the same possible with nginx and Laravel's php artisan serve? (for sure this will also need a process manager that will restart the app in case it fails.
It is possible, and somebody asked about it: How to use "php artisan serve" in a remote server - DigitalOcean. You can do a similar thing.
artisan serve is a wrapper for PHP’s built-in server, and while this is fine for pure educational reasons, “It is not intended to be a full-featured web server. It should not be used on a public network.” See Built-in web server for more.

How to host nodejs services into nginx server in VirtualMachine?

I wrote some nodejs services in my ubuntu local.Now I want to deploy my nodejs services into nginx server in my seperate VM.I set up the nginx in my virtual machine.How can I pull my nodejs services to nginx server and how to connect these api's through postman. I getting confusion at nginx config file.
You should setup a reverse proxy with nginx to redirect the traffic to you node application. Install node on your VM, copy your application and install all the dependencies using npm install. Afterwards, you should start the node application using node index.js where index.js is the entry point of your application. You could also use a process manager such as pm2 to start the application. Then, you have to setup the reverse proxy with nginx which is redirecting the traffic to the port of your application. (In your sample code 3000). The application should now be available on the IP of your VM. Below you find a minimal example configuration for nginx.
server {
listen 80;
server_name domain.com;
location / {
proxy_pass http://127.0.0.1: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;
}
}

Resources