简体   繁体   中英

How to point my node.js app to a non existing domain

I have an app running on a server where I access using the servers ip. But now I need to have a subdomain configured in order to make an external API work but I have no clue of how achieve it.

Now I access to my server using IP -> XX.XXX.XXX.XXX:3000

And I need to change it for something like -> myapp.companyname.com

You don't, because the Internet doesn't work that way.

You create the subdomain by configuring the DNS server for the domain to point that subdomain at the IP address.

If you want to change the port number (from the default of 80 to 3000) without putting it in the URL itself, then you need to change the Node.js program or put a proxy server in front of it.

This is indeed a notorious problem with distributed web development. Presumably your API requires you to register your own hostname in some sort of allow-list, and then checks incoming requests for matches to that allow-list. (Why? Cybercreeps.)

You need to find out the IP address of your development machine (not 127.0.0.1 , that's the loopback IP and every machine has it). It's OK if your development machine's address is on a private network, like '192.168.0.20 for example. Give the command for example. Give the command ifconfig and look for the address (it's ipconfig` on Windows).

You then need to put that IP address into a DNS server.

Here's a free way to do that.

  1. Create a FreeDNS account by visiting https://freedns.afraid.org/
  2. Click on Subdomains.
  3. Click the Add link.
  4. Create a subdomain hostname under one of FreeDNS's public domains. Maybe javier.ortega.mooo.com is a good choice
  5. Put your machine's IP address into it.

Then, use https://javier.ortega.mooo.com:3000 to hit your development machine's nodejs app.

You can pay FreeDNS to register your own domain name and use that if you prefer.

我需要的解决方案是从 -> system32/divers/etc/hosts 修改文件主机,并在那里添加与我正在寻找的 ip - 域关系相关的配置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM