Report this

What is the reason for this report?

Express js ip canonicalization

Posted on August 21, 2021

Im using MERN stack to build a web app. and its being hosted on a vps, and connected to a domain name. the problem is that there is two versions of the app. one on the ip adress of the vps and the other on the domain name. and this is not good for SEO. and i cant seem to find good resources on ip canonicalization or rediercting to domain name.

normally on an apache server i would use .htaccess but thats for apache. is there an equvialnt to .htaccess for expressjs. ? or any other way i can achive that.

thank you.

express



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!

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.

Hello,

What I would usually do is to use Nginx as a reverse proxy. This will also allow you to install an SSL certificate for your website using Let’s Encrypt and certbot.

You can follow the steps on how to do that here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-20-04

Once Nginx is in place, you could use the following server block to do the IP to domain redirection:

server {
    listen 80;
    server_name your_ip;

    return 302 $scheme://yourdomain.com$request_uri;
}

Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.