HTTP server for site

Started by mickyrobert, Nov 29, 2022, 07:52 AM

Previous topic - Next topic

mickyrobertTopic starter

The question is probably as stupid as possible, but I sincerely need an answer!
I decided to create a web project, and the HTTP server plays an important role in the scheme of work of this project
, and therefore I am interested, is it enough just hosting or will the server also need to be rented?


I'll tell you secret number 1: in any web project, the server plays an important role. Even just giving a picture from web hosting without it is quite difficult.
For this simple reason, almost all hosting companies provide a configured server.

Everything in the world is limited by something. There are servers with different conditions, prices, equipment, choose what suits you.
Secret number 2: At the initial stage, even a megaproject will have near-zero traffic. And the issue of switching to a more powerful package of services is solved within an hour.
So spending money prematurely on powerful servers is a guarantee to waste money.


http web server is a program, there are a lot of them, and for the most part they are free, you do not need to buy anything separately.
The most popular web server is nginx - I strongly advise
The most famous for beginners are apache or Microsoft IIS

I strongly recommend choosing linux as an operating system, especially since it's free (if you don't choose some redhat, I don't mind anything, just before you buy anything, you need to understand why you're doing this)
Usually the application should not know under which web server it runs, i.e. it does not bind you, but of course it is possible, for example microsoft likes to bind developers to its products and if you do it thoughtlessly, it turns out that you have to buy a bunch of expensive licenses (i.e. the web server is free as a service but on a server with an expensive license.

The web server usually has two main ways of working with the program (ok three, it's below) - the plugin launch mode (when the web server is able to launch a web server application written in its language, i.e. it knows how and works in its own way) and cgi, when the application can be in any language, even a binary, just the web server runs it on each request and redirects the input output from the browser to it as a standard console input output.
The first approach allows in many cases to greatly optimize the work... although there are situations when the second one is more effective. There is a 'static' mode - the distribution of files by a web server bypassing a web application, thanks to good optimization, files are distributed as efficiently as possible when a web application consumes processor time (ultimately, that is the most 'expensive' resource, along with RAM).

If the project is not highload (there are millions of active users) then on the same machine they usually combine both the web server and the web application itself, moreover, in some situations this application can take over the function of the web server, but they do not do this, because this is an additional point of failure and therefore they still put the web server in proxy mode (the world connects to nginx and it already redirects according to the settings requests to the internal application server)

p.s. at the time of development, when using, for example, the same php as a backend, you can use the built-in web server in php itself (run php -S - will launch the http server on port 8080)
there are also 'one-liners' in almost any programming languages, so that you don't I chose, for the time of development, a simple script can be a web server.

upd. along with web hosting, it is necessary to think about who will administer the server, if the hosting is universal vps/vds, then setup and support by default is usually not included in the tariff, but SaaS hosting services that offer not the server itself but a service, for example hosting web applications, may include administration in the tariff (in the cheapest options are a web panel, an interface in the provider's console where typical tasks are solved in a mouse-cutting way.


Well, if you limit yourself to java, then resin, tomcat, jetty, you can still continue.
But I outlined the essence — to show what a Socket, InputStream, OutpuStream, Thread is.
The http server was chosen by me only because it is closer to the forum than some abstract tcp server.
Although I would never advise anyone to use, for any purpose at all, there are things that die off, it's dead code that is absolutely useless, even from the point of view of learning.

I also want to note that writing examples has nothing to do with bicycles.
In general, formally, of course, you are right, the task was set that way (to quickly make an http server).
But maybe I didn't exactly formulate the problem statement for my solution, but I wanted to show people exactly this code, it is useful and understandable, and someone even liked it.