Search code examples
nginxwebserverportsearch-engine

How actually server ports work


Imagine we have a hosting containing:

  • a search engine running on port 5678 (it's required this port it's open in order to work).
  • nginx running on port 80.

When a user connects to our website and search something on it, he is only connecting through port 80, but never through 5678. We can check this running "netstat -an".

So my question is: If the client it's never connecting directly with the search engine's port, why we need to keep it open?


Solution

  • Normally client requests are coming to your web server (port 80 or 443), and your web server (your php,or your java code) has a logic to connect to your search engine and send back the result to the client via port 80/443 (local socket connection, if web server and search server running on the same server). so clients need not to connect directly to your search engine port (5678). (from external networks). may be your web server internal interface and search engines internal interface connect locally via local s socket connection.

    I'm not sure how you run your web server and search engine, is it two different servers or nginx act as a load balancer and send the client request to your multiple search servers. i think your search engine port use internally to communicate with your web server hosted software. or may be you run both nginx and search server on the same server.

    other guess is your firewall or router forwarding port 80 request to your search server port 5678 (port forwarding).

    try this on your search server

    netstat -pant 
    

    this will give your all connection details, like local address,foreign address,state, and PID/Program name

    Hope that helps