Score:0

What is the order in which apps respond when I visit DOMAIN:PORT on my VPS?

dz flag

I have owned a VPS running Ubuntu for nearly half a decade, and I have a working knowledge of the networking aspect - but there are many holes in my understanding.

When I visit DOMAIN:PORT I understand that the request is routed to the IP in my A-record specified in my nameservers, and consequently reaches my VPS - but I don't completely understand what happens after that:

  1. How does nginx then receive the request? Is there some hardware level functionality that routes it to the configured web server?
  2. If I have multiple webservers running, say nginx and apache - what decides what takes precedence?
  3. Does nginx then intercept all incoming requests? Say I have ufw allowing 8000 - then is that DOMAIN:8000 request routed through nginx? Or can it hit some other say node server running locally on that port?

These are questions I have puzzled over without being able to figure out what to google for.

Any pointers in the right direction will be much appreciated.


P.S. Mods, I looked at the suggested related questions and I feel like none address my specific set of questions. Feel free to correct me in the comments, if I'm wrong.

Score:2
jp flag

nginx (or Apache) tells the kernel that it is listening on a specific port by calling listen(2). The port number is configured with listen directive in the nginx config (Listen for Apache.). Only one process can listen for a specific port, so there is no order, the second program attempting to listen on the same port will fail with EADDRINUSE (Address already in use).

dz flag
Ah I see. So if I don't set nginx to listen to say port 8080 - and spin up some other service to run on that port - should I be able to reach that service directly from the outside?
jp flag
If that service listens on the external IP or all IPs and the port isn't blocked by firewalls then you should be able to connect to that port from outside.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.