Home  >  Q&A  >  body text

nginx - How does the node server obtain the port number of the incoming link?

The domain name accesses the node server through nginx proxy as follows:
www.xxx.com ---> 192.168.1.131:7819

How do I get this 7819 on the node server?

My current acquisition code is as follows:

  app.use(function (req, res, next) { 
     var host = url.parse(req.headers.host).host;
  })

In this case, there is no problem when accessing directly by IP.
If accessing by domain name, the domain name obtained by req.headers.host is directly the domain name

nginx configuration: b.t.wzhuanyun.com --> http://localhost:6120

为情所困为情所困2713 days ago439

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 17:17:42

    Do you mean you want to get the port that the node is currently listening on?

    reply
    0
  • Cancelreply