Home > Blockchain >  How are applications (which accepts different types of requests like http and smtp) deployed on diff
How are applications (which accepts different types of requests like http and smtp) deployed on diff

Time:11-07

I'm a beginner in all these http and tcp/ip thing. So there maybe many things in these questions that may not make sense or are totally incorrect.

First I will add all the questions I had in mind since, I could not put them on title.

I work on django (python framework) for web development.

I'm confused as to how servers work. And how is the destination port is decided through the url?

MAIN Q : What I have learned so far is that through DNS we get the ip address of the website. And port (Both destination and source) are decided by the TCP. And sent through TCP headers. But how does it decide which port should it go to in a server(i.e. destination port).

MY ANS TO ABOVE QUESTION : After spending lots of my time, I have come to know that, http requests default to 80 and https defaults to 443 and similarly other types of requests also defaults to some port. So we can figure out the ip address based on this.

But this rises another question in my mind.

Another Question : I have also built a simple django website and deployed it on pythonanywhere. But I deployed it as a whole application. Suppose my django application accepts different types of requests like HTTP, HTTPS, SMTP, etc. Then how will the port for these specific tasks be decided? Because all these requests will come under single application, so they should run on the same port. I don't think the server will change anything in the application itself. So how will the destination port now be decided?

NOTE : I'm not sure if it is possible to make an application in django which accepts different types of requests. But it should be possible because we can create different app - with startapp and run on different url.

Where ever I read, it said that the default port for http is 80, then that means it should also be possible to change it?

MOST IMPORTANT QUES AND TO SUMMARIZE ALL DOUBTS Suppose I have a project which accepts different requests. And I want to deploy it on server then how will http requests and smtp requests are separated? Do I have to manually make different apps and then deploy on different ports or something? If not and everything runs on same port, then how is this port decided in the browser? Suppose my domain name is xyz.com then how will the specific port be accessed on the server?

Basically how is a destination port decided?

CodePudding user response:

As you have already seen, protocols generally have a default assigned port (80 for http, 443 for https, 25 for smtp, ...). The main protocols in use on the Internet have their port assigned by the IANA.

Some applications also use a port by default (for example, the database service PostreSQL is configured by default to use the port 5432). https://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-sg-en-4/ch-ports.html

Most of the time you can omit the port, because the application you use know the default and use it for you. When you ask your web browser to send a request to http://example.com, behind the scene the request is sent to http://example.com:80.

You can configure your applications to listen on a different port than their default. People might want to do this for different purposes (non-exhaustive list):

  • for security (changing the port used by a service to make harder for attackers to know this service is present -not using port 22 for ssh)
  • because some port ranges require some privileges. Your operating system require a root/admin account to use the ports below 1024 (that is why development tools uses some exotic ports by default -as 8080 or 8000 for web server-, the use of non-admin account is expected). Most ISPs block port 25 on their Internet boxes to prevent spam. Etc.
  • because of conflicts (the port is already taken)

Changing the ports this way can be configuration-heavy (you have to configure the service and all its clients).

Now, the other part of the question : how can the same port be used by different services?

If you want to expose different services on the same port you can use something like a reverse proxy. It is an application that listen on a port and redirect the traffic based on rules, and sometimes they offer the possibility to modify the content (to name a few: Traefik, Caddy. General web servers also have reverse proxy capabilities: Nginx, Apache with mod_proxy, ...).

For example, imagine you have 2 web applications and you want them to be accessible on port 80. You could configure these applications to use different ports (let's say 8080 and 8081), have the reverse proxy to listen on port 80 and redirect requests based on the url used (it could redirect app1.example.com:80 to localhost:8080 and app2.example.com:80 to localhost:8081). Only port 80 has to be accessible from the outside.

  • Related