将域指向我的远程Node JS应用程序? [英] Pointing a domain to my remote Node JS application?

查看:104
本文介绍了将域指向我的远程Node JS应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力解决如何在Ubuntu 10.04 LTS服务器上部署Node JS。我已经阅读了许多不同的博客和文章,解释多种不同的方式。大多数情况似乎过时,或者似乎没有真正的工作。



似乎最简单的解决方案是使用像Forever这样的东西? ...或者与Monit或Supervisor进行Upstart。这是正确的吗?



我仍然不明白的一件事是没有使用像Ngnix这样的东西,实际上如何得到我的域名(例如example.com )实际上指向我的Node JS应用程序并运行端口?



非常感谢任何指导。我不是专家,所以请原谅我在这里的缺乏知识。 (我正在尝试我的最好!):

更新:我问这个问题的原因是在我的服务器上,我有Ngnix为我的静态/ Django项目运行。我想使用相同的服务器为一些例子Node JS应用程序我在搞乱。我已经遵循关于vhosts和Connect with Node JS的链接,这是一个很好的一点,但是我仍然不明白我将如何获得我的一个域来实际指向我的服务器上的Node应用程序? p>

解决方案

您需要将域名的概念与实际服务器分开。域名 指向服务器。当浏览器(或其他客户端)要求example.com时,DNS将查找相关联的IP地址,并将浏览器定向到该IP地址的服务器。



浏览器然后选择通过查看URL发送其请求的端口。例如,对example.com :345的请求将选择端口345.如果未指定,默认情况下,使用HTTP时,使用端口80。



所以浏览器已经通过端口80发送了请求。现在,在您的服务器上,有一个程序侦听到该端口。对你来说,这将是nginx。 Nginx读取请求(哦,你正在寻找index.html),并返回你请求的内容。



在您的场景中,Node.JS替换Nginx。对于Node.JS来响应,还需要收听端口并进行适当的响应。这就是你的代码:

  require('http')。createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text / plain'});
res.end('Hello World\\\
');
})listen(1337, 127.0.0.1);

这将启动一个服务器,在端口1337侦听。任何针对example.com :1337的请求将是这个Node.JS应用程序使用Hello World进行响应。



tl; dr:您的域名已经指向您的服务器。您可以在example.com:1337访问您的应用程序,其中1337是您的端口。


I'm trying to work out how exactly to deploy Node JS on my Ubuntu 10.04 LTS server. I've read many different blogs and articles that explain multiple different ways. Most seem out of date, or don't really work it seems.

It seems that the simplest solution is to use something like Forever? ...or Upstart with Monit or Supervisor. Is that correct?

One thing that I still don't understand though is without using something like Ngnix, how would I actually get my domain name (such as example.com) to actually point to my Node JS application and it's running port?

Many thanks for any guidance. I'm not an expert with this, so please excuse my lack of knowledge here. (I'm trying my best! :)

UPDATE: The reason why I'm asking this is on my server I have Ngnix running for my static/Django projects. I'm wanting to use the same server for some example Node JS applications I'm messing around with. I've followed the link about vhosts and Connect with Node JS, and this is good to a point, but I'm still not understanding how I would get one of my domains to actually point to this Node application on my server?

解决方案

You need to separate the notion of the domain name from the actual server. The domain name points to a server. When the browser (or other client) asks for example.com, DNS looks up the associated IP address and directs the browser to the server at that IP address.

The browser then chooses which port to send its request through by looking at the URL. For example, a request for example.com:345 will select port 345. If left unspecified, by default, when using HTTP, it uses port 80.

So the browser has sent its request through port 80. Now, on your server, there is a program listening to that port. For you, it would nginx. Nginx reads the request ("oh, you're looking for index.html") and delivers back the contents you requested.

In your scenario, Node.JS replaces Nginx. For Node.JS to respond, it would also need to listen to a port and respond appropriately. That's where your code comes in:

require('http').createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, "127.0.0.1");

This starts a server, listening at port 1337. Any requests directed to example.com:1337 would be responded to by this Node.JS application with a "Hello World".

tl;dr: Your domain name already points to your server. You can access your application at example.com:1337, where 1337 is your port.

这篇关于将域指向我的远程Node JS应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆