Phusion passenger does not start the node app.
For error detection and to exclude my own node app errors, I have therefore used the demo app of phusionpassenger.com and the implementation description of the passenger library:
- I implement it on our own server / Infrastacture Ubuntu 16.04 LTS server (Xenial)
- we use Nginx integration mode
- For test purposes I use the open source version of Passenger
Here is an extraction of my custom generated Nginx Server block configuration file - all other integrations of the example app should be the same:
Server {
# Tell Nginx and Passenger where the public directory of your app is
root / var / www / demo / code / public;
index index.html index.htm index.nginx-debian.html;
Server name it-vergabe.de www.it-vergabe.de;
# Turn on the passenger
Passenger_Activated on;
# Tell the passenger that your app is a Node.js app
Passenger_env_var NODE_ENV development;
Passenger_startup_file app.js;
Passenger_app_type node;
location / {
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 http://localhost:3000/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
Error detection: I restart Nginx and get the typical 502 Bad Gateway error if the node application is not running. Now I start the node app in a separate terminal window:
demo # Ubuntu1604srv: /var/www/demo/code $ node app
The website now works flawlessly and error free.
I have now checked the Passenger Status with the Passenger Config application and found nothing that shows that the passenger has started and under his control the node application.
Does anyone know why that is? It makes no sense to use passenger and start the node app separately ...
Thank you - Greetings from Germany!
Related
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;
}
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
}
}
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;
}
}
So here's my setup:
Digital Ocean 1gig droplet
Ubuntu 14.04x64
Dokku 1-click installer
MongoDB attached to Dokku via https://github.com/jeffutter/dokku-mongodb-plugin. Verified. I can connect to it via robomongo
domain registered in DNS records in my DigitalOcean dashboard (subdomain.mydomain.com)
website is accessible (verified via tailed app-access.log)
the basic meanjs app via their yo generator
only modified connection to mongodb server in Dokku.
push to Dokku is successful, no push errors
DigitalOcean swapfile create (1gig), no memory warnings according to dokku logs app
properly set Dokku env variables verified via dokku config app
properly set VHOST file to mydomain.com
My issue is everytime I visit the site, assets load (up until favicon.ico, along with /lib/bootstrap/dist/css/bootstrap.min.css and many others from that directory), but it stops there. The site doesn't load anything after that. The favicon shows up then nothing.
I checked the nginx logs, nothing. This is a practice website so I will be posting the nginx.conf:
server {
listen [::]:80;
listen 80;
server_name mean.ygamretuta.xyz ;
access_log /var/log/nginx/mean-access.log;
error_log /var/log/nginx/mean-error.log;
location / {
proxy_pass http://mean;
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-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
include /home/dokku/mean/nginx.conf.d/*.conf;
}
upstream mean {
server 172.17.0.62:3000;
}
I checked nginx logs, dokku logs, I got nothing. What could be wrong?
A little more googling and I found that I should issue a grunt build before I push my code to Dokku residing in Digital Ocean.
here's the discussion in meanjs issues:
https://github.com/meanjs/mean/issues/64
I am attempting to deploy a meteor app to my production server, running on Ununtu 14.04 and I am getting the following error in my log file (/var/log/nginx/error.log)
2014/12/02 16:03:38 [error] 19231#0: *4267 connect() failed (111: Connection refused) while connecting to upstream, client: 162.13.2.250, server: theserver.com, request: "GET /content/staticContent.json HTTP/1.1", upstream: "http://127.0.0.1:3000/content/staticContent.json", host: "theserver.com"
My app is fetching json content from 5 files and these are included as part of the project.
I have the following nginx configuration file. I am running nginx 1.6.2.
I should also note that visiting http://theserver.com/content/staticContent.json loads the content in my browser.
I have also run 'wget http://127.0.0.1:3000/content/staticContent.json' from the command line when logged into my production server and I can fetch the content.
server_tokens off;
upstream anna {
server 127.0.0.1:3000;
}
# HTTP
server {
listen 80;
#server_name *.theserver.com;
server_name theserver.com;
location / {
proxy_pass http://anna;
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-Forward-Proto http;
proxy_set_header X-NginX-Proxy true;
proxy_redirect off;
}
}
I also have the following upstart configuration file to run my Meteor App in a node fibre
description "Meteor.js (NodeJS) application for theserver.com"
author "Me <me#theserver.com>"
start on started mongodb and runlevel [2345]
stop on shutdown
respawn
respawn limit 10 5
setuid anna
setgid anna
script
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
export PWD=/home/anna
export HOME=/home/anna
export BIND_IP=127.0.0.1
export PORT=3000
export HTTP_FORWARDED_COUNT=1
export MONGO_URL=mongodb://localhost:27017/anna
export ROOT_URL=http://theserver.com/
exec node /home/anna/bundle/main.js >> /home/anna/anna.log
end script
My process for deployment is as follows:
On my local machine I run 'meteor build .' and then scp that to my production server to the above home directory
I then untar the .tar.gz file, cd into bundle/programs/server and run 'npm install'
Finally, when logged in as 'anna' with sudo rights, I run 'sudo start anna' given the above upstart script
On checking the generated log file, I see the generated html telling me there is a 502 bad gateway error.
When I go to the URL for the live website, I can see the loading icon I have put in place. This is the Meteor loading template I have put in place and I have configured IronRouter to use this as a loading template while it is waiting for the subscription to my collection to be filled, but this never happens because my server side mongodb instance never gets populated, for the reasons above.
Can anyone see anything unusual in the above that might be causing this 502 bad gateway error?
Running netstat -ln indicates to me that node.js is running, see below:
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN
Thanks
Have you tried using meteor-up ? It handles the bundling and upstart config for you.
The suggested nginx config for meteor-up is below, it looks pretty similar to yours (taken from Using Meteor Up with NginX vhosts).
/etc/nginx/sites-enabled/mycustomappname.com.conf
server {
listen *:80;
server_name mycustomappname.com;
access_log /var/log/nginx/app.dev.access.log;
error_log /var/log/nginx/app.dev.error.log;
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 X-Forwarded-For $remote_addr;
}
}