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;
server_name example.org www.example.org;
return 301 https://$server_name$request_uri;

server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name example.org www.example.org;

location / {
proxy_pass http://localhost:3000/login.html;
    ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem; # 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 = req.app.get('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

New contributor
helpimlost is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    Tell us about the other changes you made. Show us the nginx configuration and the error log entries. – Michael Hampton Apr 15 at 6:22
  • Michael, i have attempted to clear up any issues you may have had. what bothers me is that i literally did not change anything other than clicking one button accidentally on a web interface – helpimlost Apr 15 at 15:05
  • The "create snapshot" reboots your server, so if you'd set up a Node process to run manually instead of having it fire up as a service, that'd probably cause issues. – ceejayoz Apr 15 at 15:12

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 {
  • this fixed it. I appreciate the help greatly Michael, it saved me lots of hours of frustration. – helpimlost Apr 15 at 16:57
  • @helpimlost If it solved your problem, you can mark it as solved by clicking the outline of the tick mark so that it turns solid green. Welcome to Server Fault! – Michael Hampton Apr 16 at 1:32

Your Answer

helpimlost is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.