Move URL with redirects in Nginx

I have a node app running on http://localhost:3000. I set up ssl/https with LetsEncrypt so all requests are 301 redirected to https. Im using Nginx as web server.

I’m trying to move my URL from to

  1. How do I forward requests to AND to my node app?
  2. If users go to AND they should automatically be redirected to

How do I do this?

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You can forward your request to Node.js app by using proxy_pass directive. Look at your server block. It is usually in /etc/nginx/sites-available/default if you didn’t changed default settings. You can make it like this:

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

    location / {
        return 301$request_uri;    
    location /resume {
        proxy_pass http://localhost:3000/;

This will ensure that your traffic to and will get redirected to Node.js app. About redirection, just create a server block that will listen on and redirect to

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

This will listen only for http traffic. If you used https on, you should still make it listen on 443 with cert, so it doesn’t report Server not found error if accessed via https. This should do its job, I hope it isn’t a lot late.

After you done with changes, test your nginx with

  1. sudo nginx -t

If everything goes well just restart it:

  1. sudo systemctl restart nginx

Try and observe results, if it is not working correctly, we will make it :D Edit: added more informations.