I have a particular situation where I need to temporarily redirect from an already hosted domain on AWS to a different URL altogether.

Let me first describe my original setup:

  1. I've registered the nameservers on AWS (www.example.com) and provided some of the routing logic in Route 53 (screenshot below)

enter image description here

  1. The server is hosted on a linux EC2 with a nodeJS express server on port 5000 and a client reactJS on port 3000. Both ports are open to public to make it easier, but all traffic routes to port 3000 to see the frontend content. (see security group screenshot below)

enter image description here

  1. An SSL certificate is also registered so that the http routes to https

When I go to www.example.com, everything works as expected and I see the domain and the web contents.

Now let me describe what I want to change:

I want to temporarily be able to route all traffic going into www.example.com to a new domain hosted by Wix (www.example.app).

The easiest solution seems to be an expressJS logic. What I can do is go into app.js on my server and change the following code to this:

var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes')

var app = express();

//app.use(express.json({limit: '25mb'}));
//app.use(express.urlencoded({ limit: '25mb', extended: true }));
//app.use(express.static(path.join(__dirname, 'public')));

//app.use('/', indexRouter)

app.get('*', (req, res) => {
  // REDIRECT goes here

module.exports = app;

When I run it locally and go to localhost:5000, the redirect seems to work! Of course, when I go to localhost:3000, I get to the original webpage.

I update the code in the EC2 server and the redirect does not work. If I go to www.example.com:5000 I get a "This site can’t be reached" error. If I just type www.example.com, I get to the original webpage.

I don't know much about networking, but I think I have two open questions:

  1. Why doesn't www.example.com:5000 work when localhost:5000 works?
  2. How do I route all traffic back to port 5000 so that the redirect works?

Any suggestions would be most appreciated!

1 Answer 1


The answer was in the load balancers. I had to change my load balancer to the target for port 5000.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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