A web server or HTTP server accepts requests from users (their browsers) and provides responses to them. A lot of huge books have been written about this topic, but I will try to talk about web servers briefly and clearly. That is, I will simplify the entire article as much as possible so that it was clear even to a beginner.
The article is about external web servers, and not about the backend (for example, node.js) applications.
A simple example of a web server: a visitor enters your site's address and, after processing by the DNS server (site name => ip address), the request goes to the computer where the site is located. I think you have realized that the computer is a server that provides you with hosting.
The Web Server program runs inside the server's physical device. She receives a GET request from you, which she needs to process. GET means you want to get something from the web server. Most likely, you want to receive the content of the site page in response. A website page is text, images, scripts, page styles, meta tags, etc. The web server gives it all to you, and you see how the page loads.
Depending on the method, the server's response to requests varies.
- GET - get
- POST - create/publish
- PUT/PATCH - update
- DELETE - delete
Requests are made to specific addresses. But the results of processing requests with different methods differ even if you use the same address. For example, requests to the page /test.html with the GET and DELETE methods, they will be handled the opposite way. The first request will receive the page content in response, and the second will delete this page.
Web servers work very cleverly with data so that they are given as quickly as possible, and sometimes not given at all. For example, caching static files can significantly reduce the load on the server and speed up the loading of site pages. On the first visit, the visitor receives data that is used throughout the site (styles, scripts, images in the header and footer of the site, etc.). They are saved in the browser cache. When loading the second and subsequent pages, the server tells the browser to take them from the cache instead of downloading them.
HTTP servers also compress data, distribute the load, and can manage access to certain pages and sections of the site. And this is only a small part of their functionality. Consider the most popular web servers.
Apache and nginx
Apache was released in 1995. For a long time it was the most popular solution, but recently it has been bypassed by nginx. Both of these solutions provide all the basic functionality and differ only in very specific things that may be of interest only to highly specialized specialists.
Both web servers are free. Both have high performance, but nginx is a bit faster. The most interesting thing is that they can be used together to solve certain tasks (the so-called reverse proxy). That is, nginx accepts requests first, processes some of them itself, and gives some (more complex) to Apache, then receiving a response from it.
Each of these web servers has basic configuration files. In ubuntu, they are stored inside the /etc folder and you will not be able to access them from a regular virtual hosting. The peculiarity of Apache is that you can allow it to use settings from a file that lies in the folder with the site. This file is called .htaccess. The main nginx settings file is called nginx.conf. For more information about these sample files, see in a separate article.
Recently, some virtual hosting companies have started using only nginx and even made it possible to edit its settings. When using VDS you choose which web server to install.
The site you are currently on uses the nginx web server. Moreover, a reverse proxy is configured, since the site is a nuxt application.js + node.js. That is, an application (this site) is running on the local port 3000 inside the server through the pm2 process manager. And nginx accepts requests from visitors and gives them to the local application. The application processes requests and returns responses for nginx. Then nginx already gives the answer to you, the visitors.
A full-fledged study of HTTP, request methods, including practice - several weeks.
Installation and configuration of Apache or nginx web server on VDS/dedicated server - from 30 minutes to 2 hours.