Client/Server, DNS, Proxies

An application server to process the requests and generate dynamic content. A web server software to handle incoming HTTP requests and send back responses.
An application server to process the requests and generate dynamic content. A web server software to handle incoming HTTP requests and send back responses.

What happens when you type in a URL in browser?

  1. browser checks cache; if requested object is in cache and is fresh, skip to #9
  2. browser asks OS for server's IP address
  3. OS makes a DNS lookup and replies the IP address to the browser
  4. browser opens a TCP connection to server (this step is much more complex with HTTPS, because it includes SSL)
  5. 3 way handshaking
  6. browser sends the HTTP request through TCP connection
  7. browser receives HTTP response and may close the TCP connection, or reuse it for another request
  8. browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx)
  9. if cacheable, response is stored in cache
  10. browser decodes response (e.g. if it's gzipped)
  11. browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?)
  12. browser renders response, or offers a download dialog for unrecognized types

Popular ports

80 HTTP
443 HTTPS
21 FTP
53 DNS
22 SSH
25 SMTP for sending email
110 POP for retrieving email
Chat example with netcat

What is the client/server architecture?

  • In client/server arch. client makes the request to some resource, and server returns the response. All communication occurs over the network.
  • It is the foundations of modern internet, how computers communicate.
  • The three major components in the client-server model: presentation, application logic, and data storage.

When server sends data to client, clients bandwidth matters, because is client has low bandwidth, server will send less amount of data.

is it bad for server if client has low bandwidth? Yes, and no. Because new request will not be open from this client.

What is a web server?

Web server = software that delivers we content over internet. It receives a lot of HTTP requests, create a separate thread to handle it (redirects requests to web application), and returns a response.

Question: Why client requests first need to go to Apache Server before the request being redirected to my real web application?

Answer: Imagine you build a TKinter app, by default it can’t handle HTTP requests. This “reverse proxy” can handle incoming requests, TLS, and other security and performance concerns better than the WSGI server.

Why do we need web servers (Apache and NGINX)?

  • Handle a lot of requests.
  • Apache functions as a way to communicate over networks from client to server using the TCP/IP protocol.
  • You web app will focus on business logic.
  • Web servers also used as a load balancer.
  • They also provide the security. We are hiding our app architecture.
  • SSL/TLS are handled by them.
  • JS/Python is single threaded.

How Python Flaks web app works?

https://flask.palletsprojects.com/en/2.2.x/deploying/

Flask is a WSGI application. A WSGI server is used to run the application, converting incoming HTTP requests to the standard WSGI environ, and converting outgoing WSGI responses to HTTP responses.

WSGI servers have HTTP servers built-in. However, a dedicated HTTP server may be safer, more efficient, or more capable. Putting an HTTP server in front of the WSGI server is called a “reverse proxy.”

How DNS works?

DNS query → to find out IP address of server, then client/browser can communicate with server

DNS record sets
What happens after I update name server in a registry?
  • One IP address can be associated with many domain names. And for this reason we have HOST in HTTP request.

Forward and Reverse Proxies

  • A forward proxy sits between a pool of clients and the public internet.
  • A reverse proxy sits between the public internet and a pool of servers.

A forward proxy is a server that routes users' requests to the desired destination. It is typically used to allow users on an internal network to access external resources such as websites. A forward proxy can also be used to bypass content filtering algorithms, allowing users to access blocked content.

  • Enforcing “terms of use” on a network
  • Blocking malicious websites
  • Anonymizing network traffic by using the IP address of the proxy instead of the client

A reverse proxy is a server that routes requests from the Internet to a group of internal servers. It is typically used to provide additional security and to hide the IP address of the internal servers from the public Internet. Reverse proxies can also be used to provide load balancing and caching to improve website performance.

  • Anonymizing the cluster servers
  • SSL termination
  • Load balancing
  • Caching
  • Filtering requests
  • Attack prevention (e.g. DOS detection)

Proxy vs VPN Servers

Proxy servers act as a middleman between the user and the Internet, routing all traffic through their server and allowing the user to access any blocked content on the Internet. However, proxy servers do not offer any encryption, so the user's data is still vulnerable to interception by malicious third-parties.

VPN servers, on the other hand, provide strong encryption to ensure that user data remains private. They also allow users to access blocked content and to virtually change their location, making them a great choice for accessing geo-restricted content. The downside is that VPNs can be slow, due to the encryption and re-routing of data.

Firewall

A firewall is a network security system that monitors and controls incoming and outgoing network traffic based on predetermined security rules and policies.

Firewalls are often used to prevent unauthorized access to a private network. They became a standard part of corporate, governmental, and personal networks.

They can be used to filter traffic on the basis of source IP address, destination IP address, port numbers, and other parameters.

Outgoing traffic from network, examples: outbound = “исходящий

  • Firewall rule might allow all outbound HTTP traffic to a specific web server, but block all other outbound traffic.

Incoming trafic to network, examples: inbound = “входящий

  • Firewall rule might allow all inbound SSH traffic from a specific IP address, but block all other inbound traffic.

Reading:

SuperMade with Super