node js app issues after AWS Instance snapshot

helpimlost asked:

I had a node.js app with nginx running totally fine on a domain i purchased. It was run on an ubuntu server and all was well. I accidentally clicked “create image” on the aws site and ever since then the site doesn’t work. The local ip address through port 3000 is working as expected, but the domain is not. It is loading the first html file but cannot GET the stylesheets or javascripts that go with it and none of the css or javascript files are being loaded, rather they are all returning 404. I uninstalled/reinstalled nginx and such but have not had any luck. any ideas? I don’t want to change any code or such if possible, as it was working TOTALLY as expected/desired before this. I would like to express again that literally nothing other than clicking one button on aws has caused this issue

here is a config file for nginx

server {
listen 80;
listen [::]:80;
return 301 https://$server_name$request_uri;

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

location / {
proxy_pass http://localhost:3000/login.html;
    ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

ssl_session_cache shared:SSL:5m;
ssl_session_timeout 1h;
add_header Strict-Transport-Security “max-age=15768000” always;


also, here is what was working for my app.js
this may be a good time to ask if i’m doing everything ok, im sure it can be improved as I am still just learning

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser')
var logger = require('morgan');
var User = require("./models/user");
var db = require('./db.js');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var devicesRouter = require('./routes/devices')

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');

app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/devices', devicesRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error ='env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);

module.exports = app;

Here is what the server responds when I use it (the first one is me on local host port 3000 and the second one is where it gets all funky, it looks like its trying to access /login.htmlstylesheets/login.css instead of /stylesheets/login/css

My answer:

Well, the problem is pretty obvious here:

location / {
proxy_pass http://localhost:3000/login.html;

So every time nginx passes a request up to your Node app, /login.html is prepended to the URI path.

My guess is you or someone else made this change days, weeks, or even months ago but never reloaded nginx with it, and it was finally loaded when your server was restarted.

You should instead be passing to, with no trailing path.

location / {
proxy_pass http://localhost:3000;

You also should set the document root to the directory containing the root of your static files, and use a try_files to ensure that nginx serves the static files instead of Node. A better configuration would look like:

server {
   root /srv/www/myapp/public;
   location / {
       try_files $uri @node;

   location @node {

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.