If you are interested in web development, then, for sure, you have come across such a definition as a web server.
What is a web server?
Let's try to understand this issue.
The first thing to understand. A web server is just a computer program. Which is installed on any operating system and starts to perform some specific actions. Thus, you can install this program even on your computer from which you are watching this video, no matter what operating system you have installed.
What is this program for? Why do we need a web server?
The main job of a web server is to accept HTTP requests, process them, and issue HTTP responses.
What are these HTTP requests and responses?
We face this every day, and the most important program that allows you to work with HTTP requests and responses is a regular browser that is installed in our operating system (Google Chrome, Yandex Browser, Firefox, Internet Explorer, etc.) .
Those. requests to the web server and responses from it that occur over the HTTP protocol. This is a special set of rules that allow the browser and the web server to communicate.
Surely, you could pay attention that when typing some address in the address bar of the browser. Before the domain of the site, the protocol under which the website operates is first indicated. Either http or https.
The most important thing to understand is that after you have entered the website address into the address bar of your browser and pressed the Enter key, a request to the web server starts to be executed.
It is the web server that handles these requests. This web server can be installed on the same computer where the browser is installed. Also, this web server can be installed in some other place, another computer on the Internet. There is no difference here. Simply, with the help of a browser, we access this web server and get a response.
And according to the received http response, the browser displays the contents of the web page. The response that the web server sends contains all the necessary information so that the browser can display the web page. In the form in which it was conceived by the website developer.
A web server is such a program that is a link with server technologies.
The task of the web server is to accept a request from an HTTP client, understand which file the request occurred to, process this file and issue a response to the client.
You need to keep in mind that the web server is the link between the server-side programming language. For example, the PHP language. databases.
It must be kept in mind that the database is a separate technology (program) and does not belong to the web server.
Those. the web server received a request, passed it to some server-side programming language, or immediately received a specific file. All this is processed on the server. The server received a response from the relevant services and is already sending a response to the program that sent the request to it.
You need to understand that we can make HTTP requests not only from the browser. This can be done through the command line, through certain server applications, and so on.
In addition, the task of the web server is to create a log of errors and file accesses (log).
The next web server is user authentication and authorization. The web server allows you to determine who is accessing it, whether he has access to any files.
If the web server does not have access to any files, then the web server simply denies access to those files.
The web server also contains settings on how and what files should be processed on the web server. What to do with any folder. In general, all these rules contain a web server.
Because Since a web server is a regular program, this program can be released by various developers. Those. different companies can, according to their algorithms, develop web servers that work in one way or another.
Perhaps the most popular web servers that are available today are such web servers as: Apache, IIS, Nginx.
That, in fact, is all about web servers. The most important thing to understand without going into details. A web server is simply some kind of program that allows you to accept HTTP requests and issue HTTP responses.
In this article, we will learn what web servers are, how they work, and why they are so important.
The term "web server" can refer to both hardware and software. Or even both parts working together.
At the most basic level, when a browser needs a file hosted on a web server, the browser requests it via the HTTP protocol. When the request reaches the desired web server (hardware), the HTTP server (software) accepts the request, finds the requested document (if not, reports an error), and sends it back, also via HTTP.
Static web server, or stack, consists of a computer ("hardware") with an HTTP server (software). We call this "static" because the server sends hosted files to the browser "as is".
Dynamic web server consists of a static web server and additional software, most often application server And Database. We call it dynamic because the application server modifies the source files before sending them to your browser over HTTP.
For example, to get the final page you're viewing in a browser, the application server can populate an HTML template with data from a database. Sites like MDN or Wikipedia are made up of thousands of web pages, but they are not real HTML documents - just a few HTML templates and giant databases. This framework simplifies and speeds up web application maintenance and content delivery.
Active learning is not yet available. .
To load a web page, as we've already discussed, your browser sends a request to the web server, which then proceeds to look for the requested file in its own memory space. Having found the file, the server reads it, processes it as it needs, and sends it to the browser. Let's look at these steps in more detail.
First of all, the web server must contain the website files, namely all HTML documents and related resources, including images, CSS styles, JavaScript files, fonts, and videos.
Technically, you can host all of these files on your own computer, but it's much more convenient to store them on a dedicated web server that:
For all these reasons, finding a good hosting provider is a key part of building your website. Check out the many offers from companies and choose what suits your needs and budget (offers range from free to thousands of dollars a month). You can find details in
Once you have resolved your hosting issue, all you need to do is upload your files to your web server.
Second, the web server provides HTTP support. H yper t ext T ransfer P rotocol - hypertext transport protocol). As the name suggests, HTTP specifies how to transfer hypertext (i.e. linked web documents) between two computers.
A protocol is a set of rules for communication between two computers. HTTP is a stateless text protocol.
Text All commands are plain human-readable text. Doesn't save state Neither the client nor the server remembers previous connections. For example, relying only on HTTP, the server will not be able to remember the password you entered or which step of the transaction you are in. For such tasks, you will need an application server. (We will focus on these technologies in future articles.)HTTP sets strict rules for interaction between client and server. We'll look at the HTTP protocol itself in a technical article a little later. For now, just be aware of these rules:
On a web server, the HTTP server is responsible for processing and responding to incoming requests.
Roughly speaking, the server can serve static or dynamic content. "Static" means "is served as is". Static websites are the easiest to make, so we suggest you make your first website static.
"Dynamic" means that the server processes the data or even generates it on the fly from the database. This provides more flexibility, but it is technically more difficult to implement and maintain, which makes the process of creating a site very complicated.
Take for example the page you are currently reading. The web server where it is hosted has an application server that fetches the content of the article from the database, formats it, adds it to HTML templates, and sends you the result. In our case, the application server is called Kuma , it is written in the Python programming language (using the Django framework). The Mozilla team created Kuma for the specific needs of MDN, but there are many similar applications built on completely different technologies.
There are so many application servers out there that it's hard to come up with just one. Some application servers are tailored for certain categories of websites, such as blogs, wikis, or online stores; others, called CMSs (content management systems), are more versatile. If you're building a dynamic site, spend a little time choosing the tool that suits your needs. If you don't want to learn web programming (even though that's fun in and of itself!), then you don't need to build your own application server. This will be the invention of the next bicycle.
Now that you are familiar with web servers, you can:
We have released a new book, "Social Media Content Marketing: How to get into the head of subscribers and make them fall in love with your brand."
A web server is a server that receives requests from the user and gives them responses - a document, page or site.
More videos on our channel - learn internet marketing with SEMANTICA
Any computer can be made a server. To do this, you need to install a special shell.
Requirements for the technical part are determined by the amount of allocated resources and speed requirements. The larger they are, the more powerful the computer should be.
To make it clear, let's give an analogy. You go to the library and ask for a book. The librarian finds the right one and passes it to you. The library is a server, it stores all the data. The librarian is the shell that accepted the request and sent the response. You are a client.
You can send a librarian for more information - similar to clicking on a link. The difference is that the same resource on the Internet can be read by an unlimited number of users at the same time.
Customer service is carried out according to a similar principle: when we come for a book, we can ask a librarian a question (search engine) or look into an index (YandexCatalog). This helps you find the information you need.
Its main task is to store information. Pages, files, images, text content.
Tasks:
To understand how a web server works, you need to understand how information is transmitted over a network. It is based on rules called protocols: any URL starts with a type indication (ftp, http://, https://, etc.).
Hyper Text Transfer Protocol - transfer protocol. Site pages always look like a hypertext document. It is the end result of any server or client program.
We need a machine that will process all requests. Estimate the load that the server must support. It depends on the number of visitors: the more requests, the more power is required.
There are special companies that provide hosting services. You are renting a server. You are given a quota for hosting site files.
But if you have a simple site, then you can do it on your own.
When the issue with the server is resolved, you need to bind a static IP address to it.
The site becomes available on the web server after the domain name is registered, the DNS service resolves the addresses - binding the IP address (for example, 111.111.111.111) and the domain name (www.site.com).
It is a free, freely distributed product that has a lot of advantages:
When installing, specify the name of your host, for example, localhost. In the htdocs folder, which lies inside the Apachex.x folder (where x.x is the version number), copy any html page. Or create it in notepad by entering any text and save it with the html extension.
Once the file is in the folder, open your browser and type in the address: localhost://PAGENAME.html. Your text will appear on the screen - the page is opened from the server. If you see the error "Unable to access the site", then Apache is not running. Its icon is in the tray.
Click on it and select "Play". After that everything will work.
The share of active sites operating on it is 21.13% (Netcraft research). It is mainly used by large companies and professional developers: Yandex, Mail.ru, Rambler, etc. NGNIX can withstand a huge load of visitors, is reliable, safe and thoughtful.
It is distributed freely, but paid versions of Plus have appeared, costing from $ 2,500.
His fame is provided by the big name of the developer. It is a set of web services and is integrated with Windows. The native programming platform is ASP.NET, but you can implement an alternative, such as PHP.
Full hosting requires the installation of a server operating system from Microsoft - Windows Server. The 6th version was not intended for hosting at all, full support began in the 7th. It is purchased automatically along with the operating system and depends on its characteristics.
For novice programmers and developers, tools are created that allow you to deploy a web server on your computer in a few clicks.
Over time, any web developer ( blogger, web designer or web programmer) will need a special test site where you can practice without any problems site development or testing another web project. Some beginners use their paid hosting resources and host at least two sites there. one worker ( basic) and the other ( additional) for testing. The test site is subjected to various tests ( installation and verification of many plugins, themes, scripts and so on).
As a result, with this layout, the main working site suffers greatly, since most of the hosting resources are consumed by the test project. However, there is another way that will allow lossless ( both financially and resource-wise) to test their sites, and we will now consider this method.
You probably already know that in order to put your site on the Internet, you need to register a domain name, buy hosting, that is, disk space on some computer with a high-speed connection that can run PHP scripts. For sites to work properly, PHP and MySQL must be installed. All this is not available on a regular computer. How can HTML and PHP files run on your computer?
A regular file can be opened with Notepad++ or even with notepad. There, write something inside, save it, and then, without any problems, open this file in your browser and see how this file would look like hosted on the Internet. That is, we already see a working HTML page. In it, we can create a certain design, content and monitor the project without an Internet connection. In fact, we already have everything. If we want to run a PHP file using a browser, then nothing will work for us, since PHP scripts in the Windows operating system will not work without additional software.
All this is not available on a regular computer and thus there is no possibility to work with your web projects. Therefore, some beginners start spending money on additional resources of their paid hosting. But what about in this case? The answer is simple - there are special programs with which you can install your dedicated server directly on your computer.
What's happened server and what is the difference between a local server and what is on the network. In our case, the server does not mean a computer, but a special set of programs that ensure the optimal operation of the site. In order for the site to work, we need to install it in a special allotted place on the server (). That is, we upload the website files to a remote computer. However, without special server programs, our downloaded files will not be visible on the network. Now, for such purposes, we will create our own server on our home computer.
For this we need special programs. But which ones are better suited and what difficulties can they cause in further work? For reference, below I present the best web servers in terms of popularity around the world. However, this does not mean that they need to be installed immediately. I'll explain why later!
Currently, there are several solutions on the market from a variety of manufacturers:
Of course, there are many other similar programs, but the share of their use and trust among users is not as high as these. Unfortunately, one such program is not enough for you. Not only is it advisable to use them to work with large projects, but it can also be difficult to install and configure. In addition, in addition to such servers, a separate installation and configuration of some programs is also required ( for example, to work with a database). All this causes significant difficulties for many users. How to be in that case?
At the moment, there are many different distributions that can make life easier for any novice webmaster. They are very easy to install, easy to use, less demanding on resources and contain the necessary software elements for the best work.
That is local server It's not just one program not one specific web server), but a special collection, which includes lightweight versions of complex server programs. Usually the assembly includes: the server itself ( mostly Apache, but there may be others), PHP compiler ( with it, the browser can read the codes and assemble the page), database components, various installers, and many other programs. All this greatly simplifies the matter, rather than if we installed and configured each program separately.
In addition, separate modules can be connected to the basic packages of local servers to expand the functionality. Another important feature is that on some servers it is possible to work from a removable flash drive. In general, such builds are very well suited for rapid website development, testing small projects, and sometimes even large ones.
Here are some builds you might find useful:
So, these were the most popular web servers that deserve attention among webmasters. As you can see, there is a lot to choose from here. You can download the server you like and find out in detail the composition of its assembly on the official sites that were indicated in the description. I recommend that you download assembly data only from official sites, since other sites may post non-working distributions or with some kind of viruses. Now, many will no longer want to “force” their hosting, because with such software the process of creating sites and web applications will become more interesting and exciting! In general, study and implement!
P.S. What server do you use to test your projects? If you know any other good servers, then write in the comments about them. I will add them to the general list later.
This article will be useful to those people who already have their own website, or who are planning to open it. The article will be of particular interest to ambitious webmasters who feel that the high point of their project is just around the corner and want to prepare for the influx of page visitors.
Even those who still only dream of thousands of users on their site must have wondered: “How many users can my site withstand if they come in at the same time?” I immediately recall the well-known expression “Habraeffect” - the phenomenon of failure of a site that was not ready for numerous transitions to it after a link appeared on the Internet.
Let's assume that the site already exists (or will soon be): where to place it? Should it be classic hosting or vps server? If vps, then which one and how best to set it up? Or maybe there is no difference at all and it is easier to choose what is cheaper? In this article, we will look at several options and in practice make sure which one is best for our site.
We will experiment: set different modes of server operation and measure performance. We will simulate the load on the site using the Loaddy.com service. There you can set the number of users, the increasing type of load, and the schedule will show how the server responds to them. It is believed that one user generates approximately one request to the site within 10 seconds. As a test site, we will take a demo online store on cms moguta. It will be filled with test “products” that are displayed on the main page according to several criteria (that is, when the page is being formed, work with the database is in progress, etc.). One way or another, this will allow you to compare the modes with each other.
As a test site, we will create a vps server on Ubuntu OS. Its configuration will be . We will assume that such entry-level servers are created in most cases for new projects. The test version of the online store will be available at the ip address http://130.193.44.219/
Classic hosting will also come in handy, on which we will also upload the same online store in order to test it. You can follow our path yourself and run the same tests on your project!
Since in most cases a control panel is offered along with vps, we will make the main settings changes in it. On the vps server, 3 modes of operation are available to us:
Errors appear when the number of visitors exceeds 50 people. Hosting stops giving content, and if you go to the hosting control panel, we can see something like this:
Your site has been restricted in the last 24 hours. Processor resources were limited for your site. You have reached the input process limit (number of simultaneously running PHP and CGI scripts, scheduled jobs and console sessions) 126 times.Well, of course, hosting is hosting, especially inexpensive. You can, of course, find a tariff that will provide more opportunities, but all this must be taken into account, in some way you need to find out the exact data of the restrictions, and from each hosting provider.
Problems start when the number of users exceeds 90. If we log into our server via ssh and at that moment look at the list of processes using the top command, sorted using Shift + M (by the amount of memory consumed), we will see something like this:
We see that the apache2 process has grown into many children and they have eaten all the RAM of our vps server.
Here you need to make a small remark. The fact is that for the Apache server there is theoretically a mode that allows instead of this a large number of child processes for each connection to create several so-called multithreads, each of which would serve several connections. This mode is called worker, in contrast to the default prefork. But it’s not easy to install it, it’s impossible to do it in ISP-type panels, and if you get puzzled and try to do it via ssh, it turns out that for this it’s not enough to turn off prefork and turn on worker, you still need a thread-safe version of php. And if modules like Zend or IonCube are used, then they must also be thread-safe. Anyway, the official PHP site does not recommend setting this mode.
A bleak picture emerged. The server refuses to give out content already with 55+ visitors, the RAM is all eaten up by the “php” processes. Next comes an attempt to restore functionality, but still everything ends in almost 100% failures.
Exactly what is needed! 100% availability, while the download speed and server response time are at acceptable levels, although they increase with increasing load. Nevertheless, the server copes!
Let's look at the process table at the time of the maximum load on the server:
We see that we still have a margin of available RAM. And php-fpm7.0 child processes do not grow in large numbers, but are limited to 5 instances, each of which serves several threads.
Well, it looks like the "winning mode" is defined. Let's find out how many simultaneous visitors our server can serve in this mode. But before that, let's do a little "tuning". Firstly, since apache is not used for such server operation, it can be completely disabled. We will do this in the ISP control panel in the "System - Services" section. Secondly, let's change a little the principle of starting php-fpm processes. It is dynamic by default. This means that child processes will hang in memory even when they are not needed. At the same time, the memory is not freed, and over time, these processes can grow more than we would like. Therefore, it is proposed to set the “ondemand” mode - on demand. And set the number of child processes and timeout for them.
To do this, you will need to go to the server via ssh and register these settings in the php configuration file. It is convenient to do this in a file for the user for whom the domain was created in the ISP.
It is usually located in /etc/php/7.0/fpm/pool.d
So: sudo nano /etc/php/7.0/fpm/pool.d/www-root.conf
We see the following default settings:
pm = dynamic pm.start_servers = 1 pm.min_spare_servers = 1 pm.max_children = 5 pm.max_spare_servers = 5
To make ondemand mode work, you need to replace this with:
pm = ondemand pm.max_children = 5 pm.process_idle_timeout = 10s
And restart php-fpm with the command
sudo service php7.0-fpm restart
After that, php-fpm7.0 processes will be created on demand (when there is a load), their maximum number will be = 5, and after 10 seconds of idle time, the process will be killed, freeing up RAM.
Just in case, let's run our test again to make sure that all this amateur activity did not affect the performance of the site for the worse:
Now let's run Loaddy with a lot of visitors to see how many connections our server can handle:
The good news is that all requests were processed, albeit with a long delay, with a large number of them per second. Server response time is approaching 10 seconds with 190+ requests But let's remember the apache mode graph, where we got 4 seconds of server response already with 80+ users, while in php-fpm mode similar lags are observed with 130 requests, which we specifically highlighted cursor on the chart above.
But this is the same VPS.
top process table at the end of the test (with 200 users):
Note that after the end of testing, the memory used by pfp-fpm was freed:
So our server is ready for new loads.
It must be remembered that the site is running in nginx + php-fpm mode, which means that apache2 is not used in the work and, as a result, .htaccess is not used. This may not seem convenient, but it is the fastest possible option, and search engines are better at ranking sites that are fast.
If you want to test the site yourself with Loaddy or other methods, it is available at