[英]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.我有一个应用程序运行在我使用服务器 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.
但是现在我需要配置一个子域才能使外部 API 工作,但我不知道如何实现它。
Now I access to my server using IP -> XX.XXX.XXX.XXX:3000现在我使用 IP -> XX.XXX.XXX.XXX:3000 访问我的服务器
And I need to change it for something like -> myapp.companyname.com我需要将其更改为 -> 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.您可以通过为域配置 DNS 服务器以将该子域指向 IP 地址来创建子域。
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.如果你想改变端口号(从默认的80到3000)而不把它放在URL本身,那么你需要改变Node.js程序或者在它前面放一个代理服务器。
This is indeed a notorious problem with distributed web development.这确实是分布式 Web 开发的一个臭名昭著的问题。 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.
大概您的 API 要求您在某种允许列表中注册自己的主机名,然后检查传入请求是否与该允许列表匹配。 (Why? Cybercreeps.)
(为什么?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).您需要找出开发机器的 IP 地址(不是
127.0.0.1
,这是环回 IP,每台机器都有)。 It's OK if your development machine's address is on a private network, like '192.168.0.20 for example. Give the command
如果您的开发机器的地址在专用网络上,例如“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). for example. Give the command
ifconfig and look for the address (it's
在 Windows 上and look for the address (it's
ipconfig`)。
You then need to put that IP address into a DNS server.然后,您需要将该 IP 地址放入 DNS 服务器。
Here's a free way to do that.这是一个免费的方法来做到这一点。
Then, use https://javier.ortega.mooo.com:3000 to hit your development machine's nodejs app.然后,使用https://javier.ortega.mooo.com:3000访问您的开发机器的 nodejs 应用程序。
You can pay FreeDNS to register your own domain name and use that if you prefer.您可以支付 FreeDNS 来注册您自己的域名,并根据需要使用该域名。
我需要的解决方案是从 -> system32/divers/etc/hosts 修改文件主机,并在那里添加与我正在寻找的 ip - 域关系相关的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.