Phusion Passenger: Simple / easier / faster OR Too complicated? - node.js

Simple / Easier / Faster are slogans i read every where they wrote about Passenger.
But it's really complicated to deploy.
Early 2019 i deployed 1st time, it took about a week for searching how to config
And now, 2nd deployment, 3 days already and got no luck, post that helped me config last time has gone.
Official Tutorials are so general and helps just a little and only in easy cases. Most of online tutorials are about PM2,... a few wrote about Passenger but not much to see.
I have Frontend & Backend placed in same root folder with structure like this:
Root app folder
|___client (Frontend - React)
|.......|___node_modles
|.......|___public
|.......|.......|___index.html
|.......|.......|___favicon.ico
|.......|___src
|.......|.....|___index.js
|.......|.....|___App.js
|.......|.....|___actions
|.......|.....|___components
|
| (Backend - nodeJS using express)
|___node_modules
|___middleware
|___models
|___routes
|___server.js
I'm using Nginx + Passenger + nodeJS
Config for Backend:
server {
listen 8080;
server_name x.x.x.x www.x.x.x.x;
root /var/www/tnapp/code/public;
passenger_app_root /var/www/tnapp/code;
passenger_app_type node;
passenger_startup_file server.js;
passenger_enabled on;
}
The server doesn't response and just got err
This site can’t be reached<br/> x.x.x.x took too long to respond..
Frontend config:
server {
listen 80;
server_name x.x.x.x www.x.x.x.x;
root /var/www/tnapp/code/client/public;
passenger_app_root /var/www/tnapp/code/client/src;
passenger_app_type node;
passenger_startup_file server.js;
passenger_enabled on;
}
With this frontend i got response html part, but nodjs part seems not working.
Hope someone can help me out on config this thing
i'm exhausted ##

Related

Setting Up of Nginx reverse proxy

I have a node application running on an ec2 instance. Node is running on port 5000. I want to access the api from remote.
this is nginx configuration file.
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
client_max_body_size 20M;
listen 80;
listen [::]:80;
location / {
proxy_pass http://127.0.0.1:5000;
}
location /nginx_status {
# Turn on stats
stub_status on;
access_log off;
}
}
when I try to curl using curl localhost/nginx_status
it returns
Active connections: 1
server accepts handled requests
11 11 12
Reading: 0 Writing: 1 Waiting: 0
Also when I try to access the IP in browser, it shows
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
But if I try to access the ip_address/nginx_status it shows 404 Error for example if I took IP address 123.456.789.098 in browser it shows the above mentioned message and if I took 123.456.789.098/nginx_status it will return 404 error. Even if I try curl ip_address/nginx_status it is also returning 404 error.
My question is, How can I access node application running on port 5000 from outside world?
unfortunately I only see part of your config, is there another server that listens to 80?
You don't use "default_server" for listen either, and without "server_name" I find it difficult to distinguish between them. So maybe another config with the server + port 80 as default_server takes effect. Check in your /etc/nginx/ folder which servers {..} all exist.
The proxy_pass looks correct, if the nodjs server is really listed there, check again whether it is really http or https scheme. For the correct protocol transmission of the proxy_pass.
But you should then add a control for the "stub_status" so that it is information that you do not entrust to everyone, for me it is the case that only one application has access to it internally and under another list what is not released on the internet:
server {
listen 127.0.0.1:10081 default_server;
location /flyingfish_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
I'm curious what you find out! :)

Nginx reverse proxy to nodeJS. How does Vuejs fit in?

Thanks for helping out!
I'm setting up an API server that will also function as a web-app server. (Debian 10)
I currently have nginx as a reverse proxy to my nodeJS app.
I'm thinking of using VueJS to develop my frontend single page app but I can't figure out how to tie it all together.
Should I :
use a reverse proxy to nodeJS and have my API live there
AND
use nginx to serve my vueJS web app, without the nodeJS overhead
This seems logical but I'm a bit confused, since I've never done it before.
Thanks again for helping!
Regards,
Renato
I have a website running with nodejs and vuejs which is hosted on digital ocean with nginx reserve proxy. I'm using pm2 to call nodejs apis and it works perfectly fine. As far as Vue.js is concerned, you can run build and deploy the dist folder anywhere on the internet.
Just add the following code to run front-end with nginx:
server {
root /path to your dist vuejs folder;
index index.html index.htm index.nginx-debian.html;
server_name domain.com;
location / {
try_files $uri $uri/ =404;
}
}

how to connect graphql Api to front End apps on nginx hosted on Ec2

I have an App composed of three projects with the following structure :
mainapp
->/packages
->/admindashboard
->/shopapp
->/api
I want to deploy the project on an Ec2 instance (which I'm not the administrator), so I built the admindashboard and the shopapp with :
yarn build
added Nginx and configured the /nginx/sites-available/default file like so :
server {
listen 80 default_server;
server_name localhost;
location / {
root /var/www/mainapp/packages/shopapp/out;
index index.html index.htm;
}
}
#running admin-Dashboard
server {
listen 3000 default_server;
server_name localhost;
location / {
root /var/www/mainapp/packages/admindashboard/build;
index index.html index.htm;
}
}
-this got the tow front apps to work, but I couldn't link the api.
when I run yarn dev:api-shop or yarn dev:api-admin
it shows that it's running on port 4000 but the front app's fail to fetch the data, it can't get or post to the api.
what is the correct way to deploy such project?
the project technologies are :
Admin Dashboard :
-CRA
-Apollo
-BaseUI
-Typescript
-React Hook Form
Shop :
-NextJs
-Apollo
-Typescript
-Styled Components
-Stripe Integration
-Formik
API :
-Type GraphQL
-Type ORM
thank you, and sorry if my explanation is not clear.
I resolved the problem, actually in the admin project in the .env file the API URL was :
http://localhost:4000/admin/graphql
I had to change localhost to the Ip address of the instance like so :
(example)
http://15.xxx.xx.xxx:4000/admin/graphql
and it worked, yet having two API (one for the shop and one for the adminDashboard)
I had to run one on the 4000 port and the other one on the 4001, Now it works but I still wonder if it's the proper way to deploy such app . thank you all

Deploying multiple nodeJS on Digitalocean with Dokku

I've tried to deploy two nodeJS apps on Digitalocean using a dokku droplet. I am using the "virtualhost naming" scheme but there is a problem.
My DNS configuration looks like this:
I have the main app and the admin app. I would expect to view the admin app when i visit app.example.com (I actually have a proper domain name) but I can see the same app when hitting example.com and app.example.com.
There is something wrong with nginx probably, but I don't know exactly what is going bad?
One thing I have noticed is that whichever app is installed first will be the one that example.com forwards to.
You are correct to attribute this behaviour to Nginx. I think it's due to it falling back to this config somehow when it doesn't detect a config for example.com
This dokku plugin (https://github.com/progrium/dokku/tree/master/plugins/nginx-vhosts) is responsible for rewriting the nginx.conf for each app every time it is deployed.
Nowadays it uses a template nginx.conf (https://github.com/progrium/dokku/blob/master/plugins/nginx-vhosts/templates/nginx.conf) although this is a fairly recent change so be sure your on a recent version.
You will end up with a Nginx config that looks like the following:
server {
listen [::]:80;
listen 80;
server_name app.example.com;
return 301 https://$host$request_uri;
}
I'm not currently sure why the above snippet results in the described behaviour. A work around is to setup your own nginx conf in /etc/nginx/sites-enabled/ with
server_name example.com;
but pointing to a holding page or whatever works for you.

Can't get to my nodejs server through web browser

Alright, so I setup a node.js server quite a while ago on a AWS EC2 micro server. I was completely new to it and followed various tutorials to get it up and running. It used nginx as a reverse proxy (I believe) and the server was listening on port 8124.
Now, the instance got restarted and I can't for the life of me get access to my server back. I can ssh to it. I can start the server. I can send POST/PUT requests to it through my local command line, but my web browser gives me the 404 nginx page.
This is driving me up the wall - where in the browser/nginx/nodejs chain are things breaking down?
Please help - I'm horribly new at this at it must be a single line somewhere that's broken. I just don't know enough to find it.
My /etc/nginx/sites-enables/default file simply contains
location / {
proxy_pass http://127.0.0.1:8124/;
}
Okay I figured it out. I had to go directly into /etc/nginx/nginx.conf and in the server that was there
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
I added the line
proxy_pass http://127.0.0.1:8124/;
Oh thank god. That was going to kill me.

Resources