By tjljr
I am new to Nginx and Ubuntu 16.04. I had an Nginx website up at armadasol.com with a NodeJS script. It uses a local MongoDB and PM2. I made some hard code changes on my home page and after I refreshed the website in the browser, the changes did not update. I restarted my server and now I get a 502 Bad Gateway error.
I have got the PM2 restarted. MongoDB is restarted
I use Nginx, NVM, NodeJs, MongoDB, PM2.
My nginx.conf server settings:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /usr/share/nginx/html;
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;
}
}
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Question 1) Why am I receiving a 502 error? Question 2) How do I prevent this next time I make changes in my files? Question 3) Is there a script anyone recommends that can restart my nodejs app when I make changes.
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!
Sorry, it never forwarded past the “posting screen” on my account. I gave up and figured it would never post.
Hello,
I just came across this question.
As a reference for anyone who comes across this in the future, in order to start your Node.js process with PM2 after a server restart, you need to do the following:
pm2 startup systemd
sudo systemctl start pm2-sammy
If at this point you encounter an error, you may need to reboot, which you can achieve with sudo reboot.
Check the status of the systemd unit:
systemctl status pm2-sammy
For more information, you can check out this tutorial here:
Best, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.