Created a simple server on NodeJS. How to hang it on the desired url, and not on the port?
2 answers
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 , evenmysite.loc
, even thoughyoursite.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 thenode.js
instances. > I need my server to be accessible only to me (localhost) @LightShock, then replace the DNS server with thehosts
. - 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 (Fromhttp.createServer([requestListener])
toserver.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 specifyport
, it will be80
, andhostname
, 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
|
Virtual Host
- Niki-Timofe 2:46 pm