简体   繁体   English

如何使用node.js将家用PC设置为Web服务器

[英]How can I make my home PC a web server using node.js

If you have any ideas about the possibility of allow my friend to access my node.js web page by browser from her computer .. she lives out side my town i tried one method which is 如果您对允许我的朋友通过浏览器从她的计算机访问我的node.js网页的可能性有任何想法,那么她住在我镇附近,我尝试了一种方法

var http = require('http'); http.createServer(function(req,  res){            res.writeHead(200, {'content-type': 'text/plain'});     res.end('It works'); }).listen(3000, '0.0.0.0'); //listening all interfaces

it works correctly but with the computer which locate on the same LAN network 它可以正常工作,但可以与位于同一局域网中的计算机配合使用

You could to configure your router to allow in route to your server port. 您可以配置路由器以允许路由到服务器端口。

If you have a fix IP, you don't need more things. 如果您有固定IP,则不需要更多东西。 If your IP vary along the days, you can to configure your router to use a dynamic IP. 如果您的IP随时间变化,则可以将路由器配置为使用动态IP。

I use https://www.dtdns.com/ , a free dynamic dns provider, to allow an external URL to access my home "server" (a Raspberry PI). 我使用https://www.dtdns.com/ (免费的动态dns提供程序)来允许外部URL访问我的家庭“服务器”(Raspberry PI)。

But, already, it starts at configure your router, or, also, using the tunnel listed after, by I believe configuring your modem it's more fast to access (more kb/s) than using tunnel. 但是,它已经开始于配置路由器,或者也使用下面列出的隧道,因为我相信配置调制解调器比使用隧道更快速地访问(更多kb / s)。

Better to have Linux based operating system 拥有基于Linux的操作系统更好

  1. Write NodeJS app (or download ready one somewhere) 编写NodeJS应用程序(或在某个地方下载即可)
  2. Install Nginx - This app will reply and handle all incoming connections 安装Nginx-此应用将回复并处理所有传入的连接
  3. Install Phusion Passenger ( Free version ) - This app will make sure your NodeJS application is up and running 安装Phusion Passenger免费版 )-此应用程序将确保您的NodeJS应用程序已启动并正在运行
  4. Copy your application to /var/www/yourappname on Linux and ~/Sites on Mac 将您的应用复制到Linux上的/var/www/yourappname和Mac上的~/Sites
  5. Configure Phusion Passenger 配置Phusion乘客
  6. If you have fixed (static) IP-address - you're good to go. 如果您拥有固定的(静态)IP地址-那就好了。 Just type your static address and port ( if different from :80 ) into browser 只需在浏览器中输入您的静态地址和端口( 如果不同于 :80
  7. If you have dynamic IP-address - You will need a service called Dynamic DNS, I can recommend this one but is is paid service. 如果您具有动态IP地址-您将需要一项称为动态DNS的服务,我可以推荐服务,但这是一项付费服务。 I'm sure after a bit of Googling you can find a free similar service 我敢肯定,经过一段时间的Google搜索后,您可以找到免费的类似服务

If you're doing this - first time, it may looks a bit tricky and can take a day or two. 如果您是第一次这样做,可能会有些棘手,可能需要一两天。 But after few server setups - you will be able to do same operations with closed eyes. 但是,只需进行几次服务器设置,您就可以闭眼执行相同的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的网站服务器中运行node.js而不是我的PC本地服务器 - How to run node.js in my web site server not my pc local server 我怎么能让node.js服务器在我的局域网而不是localhost上监听我的ip - How can i make a node.js server to listen to my ip on my lan instead of localhost 如何让我的网络上的其他人可以访问node.js服务器? - How can I make a node.js server accessible to others on my network? 如何故意使我的node.js服务器崩溃? - How can I purposefully crash my node.js server? 我如何使用 adonis /node.js 中的模型实例创建 create() 方法? - How i can make a create() method using a instance of my model in adonis /node.js? 如果我的模块依赖于另一个模块,如何使用node.js在客户端和服务器之间共享模块? - How can I share modules between the client and server using node.js if my module depends on another? 如何使用护照在我的node.js服务器上验证android应用的GPGS令牌 - How can I verify android app's GPGS token on my node.js server using passport 如何将运行在应用程序服务器(即JBOSS)上的现有Web应用程序与node.js集成在一起? - how can I integrate my existing web application running on application server(i.e.JBOSS) with node.js? 使用Apache之类的家庭基础服务器进行Node.js Web部署 - Node.js web deploying with a home base server like Apache 为什么我不能向我的 Node.js Express 服务器发出 POST 请求 - Why can't I make a POST request to my Node.js Express server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM