V
V
Vitya Podpriklopolny2019-06-25 21:19:19
Web servers
Vitya Podpriklopolny, 2019-06-25 21:19:19

What is a web server and how does it work?

Good afternoon
What is a server?
I understand that this is relatively speaking a computer that is located in the data center and is hosted.
There is a simple hosting - ie.
the files just lie on it and it can also process the backend (depending on the server configuration) If, for example, the server has the php language, then it processes php, etc. it's a simple hosting. You, as a guest, use its services with what is already there
. And there is a Virtual Server (VDS) - In fact, part of the server or the whole server, but completely provided to you. By the way, what is the difference between VDS and VPS? Or is it the same thing? So, here you can change the software, the backend language (for example, ruby ​​or java), and so on. And here you can do whatever you want?
I understand correctly?
And now to the questions...

  • It turns out that there are servers, and they can have Apache, Nginx, NodeJs, etc ... Is it a type of program that, like operating systems, is only on the server? Well, for example, Apache processes php, and nodejs - js files? So? What generally depends on these programs? What are their differences (at least briefly)

  • For example, there is a simple php server. How can I make js files look like php (Maybe it's nonsense, but still. I'm confused sovly) For example, pass the parameters of a post request from a form to the server in js, and so on?

  • There is, for example, openServer .. Is this essentially the same as a regular server? (Well, imitation)
    It is necessary to select the version of php in it. it turns out that the server must have php? Or how in general?

Emae, how to figure it all out? It turns out that each project has its own backend, regardless of the software on the server? and for example it interacts with the server api and php is already working here? or how??
Please help
me, thank you very much everyone!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rPman, 2019-06-25
@megamage

You wrote everything correctly and I think you understood.
Those same programs in php can be in any other programming language, moreover, there is even a class of web servers (fastcgi for example), the web began with them, which stupidly launch your program on every http request (what command line write one, and they will launch it) and pass data to it (a request or upload a file) to the stdin of the application, and return via http the response issued via stdout, i.e. your application should accept input while waiting for keyboard input, and return a response by simply printing it out. Of course, there are their own formats, but they are primitive - text format, lines, spaces, comma separators, etc., it is called the http protocol.
There are different web servers, not only php, there are those that can be written in .net (any language from this environment, of course, this is offered by the Microsoft web server - iis, asp), there are connectors to java, etc.
In its raw form, working with http requests is boring, plus calling for each program request is not efficient (for which those who do not see reactphp do not like php), and in recent years it has become the norm to run an application in your favorite programming language, which itself looks like a web server , and there are ready-made libraries for this both for php and for nodejs, including the asynchronous style of work. This is when instead of flat code writing - request, wait, answer, wait .. all logic is wrapped in an event loop, and all calls look like - start receiving the transfer, in the call parameters specify the functions that will be called when everything is over or an error occurs, and so even for working with local files (and they also came up with all sorts of async, await and promises).
An asynchronous web server, even in a single-threaded version, is in practice capable of processing a huge number of requests (in parallel), and due to the fact that for each request it does not have to pull out a bunch of data (from the database, from the cache, from sessions), since there are no expectations, data is already in the variables from the last call (more precisely, it looks like a classic desktop application that is running all the time of the user's session) and all calls occur exactly when the data for them is ready.
It’s also difficult to write a normal websocket server without an asynchronous principle of operation (in fact, there are a lot of ready-made websocket servers that wrap calls into ordinary flat request-response, but we are talking about flexibility and speed).
nodejs grew up on this, it is basically asynchronous. The web server code in its purest form is very simple and concise, the simplest helloworld is a few lines. Asynchronous libraries were also written for php, see reactphp. And they are actively promoting go for this business.
In the open, of course, they try not to put such a nodejs server on the Internet, and between it and the whole world they put nginx as a proxy, it is also responsible for load balancing, statics and https encryption.

S
Sergey Borisov, 2019-06-25
@tatiana6666

A web server is a program that receives requests (from the user) and processes them. Depending on the request, the server responds to the user or takes some action on its side.
To understand how servers work, try downloading the server and installing it, and the client. 5-6 lines of Python code for example.
Download Wireshark and see what the packets (requests) will look like on your server.
And then, you will understand everything! =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question