Created a simple server on NodeJS. How to hang it on the desired url, and not on the port?

  • 2
    Apparently not url and domain? - Vladimir Gordeev
  • one
    @Vladimir VG; Rather even Virtual Host - Niki-Timofe 2:46 pm
  • @ niki-timofe to everyone's joy apache is not the only web server. - rnd_d

2 answers 2

In order for mysite.loc in your mysite.loc to have your server (do you want other people in LAN to go to this address?), You need to deal not with node.js, but raise your local server in LAN, which, on request, mysite.loc will give out your IP address on the local network. Then any server running on your site will be available at the same address (with the appropriate firewall settings).


UPD0. In case you have several node.js instances and each must respond to its hostname, put nginx in front of the nodes.

The question is, in fact, for RutCode .

  • one
    @Nofate, well, on the computer of the TS'a through the DNS server people got, and he has 2 servers there, and both respond to any address , even mysite.loc , even though yoursite.loc , how to be ??? - Niki-Timofe
  • Not really. I need my server to be accessible only to me (localhost), like Denver. - LightShock
  • one
    > and he has 2 servers there, and both respond to any @ niki-timofe address, about two servers (as far as I can see) was never mentioned. But this is not a problem either: nginx is set before the node.js instances. > I need my server to be accessible only to me (localhost) @LightShock, then replace the DNS server with the hosts . - Nofate
  • What does it mean to replace? Do you mean do a redirect? - LightShock
  • You mean, make an appointment by host , like in Apache ?
  • If so, http.createServer([requestListener]) here (From http.createServer([requestListener]) to server.listen(path, [callback]) )
  • To be honest, I don't know what it's called) If it's simpler, then I need my server to be at mysite.loc . PS I do everything on LAN. - LightShock
  • 2
    > as in Apache As in HTTP 1.1 - karmadro4
  • @LightShock, this means that server.listen(port, [hostname], [callback]) you need to specify port , it will be 80 , and hostname , it will be mysite.loc - Niki-Timofe
  • It gives errors. Screen: s1.ipicture.ru/uploads/20120603/aA9gKVTZ.png The first time the code was like this: var http = require ('http'); http.createServer (function (req, res) {res.writeHead (200, {'Content-Type': 'text / plain'}); res.end ('Hello World \ n');}). listen (80 , 'mysite.loc'); console.log ('Server running at 127.0.0.1:1337/' ); The second time everything is the same, only the listener has become such: .listen (80, 'mysite.loc', function () {console.log ('looooggg ..');}); - LightShock
  • @LightShock - you would like to read about http for a start, if you cannot go for it - write in PHP =) - Zowie