Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi,
Great post. But after setting it all I was running into an issue: a 502 bad gateway error after strugling with it I discover in nginx error.log that it was a permission error: “nginx (13 permission denied) while connecting to upstream”… after google-it I found the solution here It was SELinux issue. I think this deserved to be shared. Thanks
Great post! I am having a weird issue; the Nginx proxy can only find my node server, if it runs on port 9000, but not on any other ports . This is my nginx.conf:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://localhost:9000;
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;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Node:
server.listen(9000, _configEnvironment2['default'].ip, function () {
console.log('Express server listening on %d, in %s mode', _configEnvironment2['default'].port, app.get('env'));
});
But if i change the two 9000 ports to for example 8080 nginx can’t find my node server???
Thanks for the great post! Question. Did you have issues with pm2 init? I cannot seem to get this to work via an ansible script. I seem to be running into this pm2 issue. It’s causing me major headaches.
Hi! Im trying to get a web server running on my Centos7 Virtual Box, but no success… I have done all the steps above, and if I type in the browser my private IP I get redirected to my running nodejs app; however, nothing happens if I type my public IP. This is my conf file:
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid;
events { worker_connections 1024; }
http { log_format main '$remote_addr - $remote_user [$time_local] “$request” ’ '$status $body_bytes_sent “$http_referer” ’ ‘“$http_user_agent” “$http_x_forwarded_for”’;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name http://63.78.220.47; #my public ip(faked)
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://10.0.2.12:3000; #private ip and listening port of my app
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;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
What am I doing wrong?? Thanks! :)
I also have problem with the startup pm2 on CentOS 7. It seems that these problems disappear if the application is run under root:
sudo pm2 start hello.js
and then:
sudo pm2 startup centos
I played with pm2, and found two working way for CentOS 7 (in your project folder index.js - main file):
# 1
sudo pm2 start index.js
sudo pm2 save
sudo pm2 startup centos
# 2
pm2 start index.js
pm2 save
pm2 startup centos
# and run the script generated in the previous code under sudo
NOT working next
pm2 start index.js
pm2 save
sudo pm2 startup centos
and NOT working next
pm2 start index.js
sudo pm2 startup centos
Hi, After setting everything up as described in above started app with pm2 but if I try to access ip from browser it gives bad gateway ( if node is under nginx ) and just dead page if url points to nodejs app. pm2 status says that app is online…
if I run app with npm ( npm start ) everything works fine, but with pm2 app is online but server is not reachable or badgateway from nginx. plz help!!!
Not sure what APP_PRIVATE_IP_ADDRESS means. To me there is only the public droplet IP and the loopback ip. But you couldn’t have meant that loopback because its the same for server. Please help my ignorance.
Hi Mitchell Anicas!
Thanks for nicely precising this tutorial. I was using forever to keep node application running but it was not reliable.
Do we need to keep port open in iptables if we use this reverse proxy method?
I’ve opened two PORT 31129 for NODE and SOCKET.IO and PORT 6379 for REDIS.
Will my application work if close these two ports?
Thanks