I have a question about using a computer as a web server. Why can a certain computer be a web server? What features make it able to be a web server? Is there any case where a computer is unable to act as a web server?
-
A network card.– el.pescado - нет войнеMar 16, 2017 at 6:26
-
1The smallest I've seen is a wifi SD card made by Apacer. It has 4MB of ram and runs linux and can respond to web requests and transmit images when it's in a camera.– user3528438Mar 16, 2017 at 13:02
-
@el.pescado Unless the client is on the same host.– Dmitry GrigoryevMar 16, 2017 at 14:44
5 Answers
Pretty much any computer can be used as a [web] server, provided it can connect to a network, and can run web server software. As a web server can be quite simple, and there are free and open source web servers, in practice, any device can act as a web server.
The bigger problem is the networking side. In order for a system to act as a server, other machines need to be able to access it. If it's just for use in a LAN, there are no concerns; however, if it's for use from the wider Internet, then data needs to be routed to it. This requires either a static IP address associated with the server (or port forwarded through a router), or an external service which can map a domain name/subdomain to a changing dynamic IP address.
(FWIW, you can buy $10 computers which can act as a basic web server.)
Of course, while any device can act as a web server, functionality of web sites can vary hugely, and a cheap device (or slow connection) may not be able to keep up with demands depending on what the specific website is.
I note that everything above talks about web servers - but the same can be said for pretty much any type of server.
-
2another problem is that cheap devices might not be as reliable as "real" servers because their components are not certified to run in a very long time and their memory doesn't have any means to prevent bit rot like ECC RAM. I've seen my colleagues leaving their computers for several months and end up in BSOD– phuclvMar 13, 2017 at 8:24
-
11Yes and no. Ive run plenty of systems 24/7 without ecc ram, and most home/small business routers - which are wenb servers as well run quite reliably without bsod. Of-course, BSOD equivalents are not that common outside the Windows world.– davidgoMar 13, 2017 at 8:53
-
9@davidgo Bugcheck errors aren't common in the Windows world either, unless you've got failing hardware or dodgy drivers. Which cause similar issues for any OS. Lost count of the number of video driver related issues on both Windows and Linux.– BobMar 13, 2017 at 12:31
-
7@davidgo BSOD is just a fail-safe, not a problem on its own. It's a last ditch attempt to prevent sneaky code/data corruption and hardware damage. In any case, anecdotal evidence is entirely useless in things like this - there's a very high chance you're never going to encounter a visible issue with this, or you'll misattribute it, and there's a huge amount of environmental factors that make it more or less likely (temperature, latitude, EM noise, electric network quality, system load, reliability of a given component). Cost and worth of ECC RAM and such is a business decision.– LuaanMar 13, 2017 at 12:50
-
15You have probably a few web servers at home already: Your router/access point, your printer, and all other kinds of configurable home automation gadgets like smart meters, IP cameras, VoIP telephones, programmable thermostats, your TV. The smaller ones give you an idea of how little hardware is needed. Another remark: Networking is not a strict requirement for a web server -- it can make perfect sense to have a server that only serves pages to users on the same machine. Mar 13, 2017 at 16:40
It's not tricky at all. It merely depends on your definition of "web server".
It's entirely possible to run a "web server" on devices as simple as a microcontroller.
Let is consider what the bare minimal web server would need to do. It would need to output some text - not necessarily even in HTML to a client. It would need to know a request is a request, and respond appropriately. You wouldn't even need network connectivity if your "client" was local. It would be an entirely pointless web server.
It would be the web server equivalent of one of these.
Adding network connectivity for a client (Ethernet is nice, but there's no technical reason you can't connect to a web server running on wifi) and being able to route from a client would be better.
A $5 ESP8266 – a cheap, minimal microcontroller with wifi can handle much of that, and maybe even basic dynamic content
I use something like that for quick file sharing using Python. It's still entirely possible to write something like this on a microcontroller or even run it on a phone.
Static content is boring. Add dynamic languages and you'd need to start thinking of heavier weight systems. Stuff that runs Linux or Windows are nice.
At this point, you're talking consumer routers, small applications using web pages at UI and all that.
A web server isn't even a complex problem and can be written in five lines of bash and run on Linux. Now doom... But any system that can run doom can run a web server.
A good web server setup capable of handling a given load is somewhat trickier.
-
11It is even possible to solder together some TTL chips and run a webserver. See this webpage for the details– JosefMar 13, 2017 at 8:36
-
7That's roughly like saying "Its even possible to bolt together some steel and build the Eiffel tower. That's so cool– Journeyman Geek ♦Mar 13, 2017 at 9:04
-
1Amusingly, your 'pointless' webserver is exactly how some help used to work for certain products :) - I can't remember examples, but there was at least one case where the help was running on a server (not just a html page rendered by a browser) and the subsequent problems that presented (my help pages don't load when my firewall is on!). Mar 13, 2017 at 11:58
-
5
-
2A raspi is higher powered than likely 99.9% of commercial web servers were in the year of 2000. And people were already doing heavily dynamic stuff back then. Mar 14, 2017 at 13:12
Bare minimum
Literally, any computer can become a web server if it has the following:
- A network connection
- A very simple web server app, like this.
But would it suffice? Now, that's the tricky question.
Serving an Intranet
For a computer to become a web server that serves modern web pages or web apps to a whole community (e.g. school, company, museum):
- Hardware capable of responding several computers at once. Maybe an old computer running Linux or Windows XP would do.
- A high-speed network connection with enough bandwidth, say 1 Gbit/sec Ethernet or 802.11g Wi-Fi.
- A good web server app, like IIS, Apache, Nginx or others. (Surprisingly, these three are free.)
But that was just a minimum for small operations. When your operation gets bigger (i.e. you get a heavier traffic and serve complex web apps instead of static pages), your needs grow. You will eventually need:
- Server-class hardware like rack-mounted servers with several Xeon CPUs and hundreds of gigabytes of RAM
- Fiber-optic networks
Serving the world outside
To exploit the Internet infrastructure to serve the whole world, you will need:
- A public IP address
- A public DNS server
- Digital certificates issued by reputable certificate authorities for establishing a secure connection
Without these, all you have is a potential web server.
-
._. I consider a raspi a bare minimum and janky as heck. Its also worth remembering many things use a web page as a UI. Your router has but isn't a web server for example.– Journeyman Geek ♦Mar 13, 2017 at 6:50
-
9Diisagree with these comments - a router IS a web server (as well as other things). By the logic of the comments, there is no such thing as a web server because any such system has other functionality.– davidgoMar 13, 2017 at 8:58
-
5The heavy CPU and other resource needs are much more about web applications and dynamic HTML generation languages - eg PHP, a common but (especially if set up the way it usually is) hilariously inefficient such language - than about web serving . A 33MHz 80486 with 16MB RAM could be made to handle a heavy load of static pages if anyone bothered. Mar 13, 2017 at 9:30
-
@rackandboneman Very well. I will clarify the meaning of "if your operation gets bigger" to address your concern.– user477799Mar 13, 2017 at 9:37
-
Programming/Software perspective:
A program that is able to listen to Port 80 on Network adapter. That runs on the OS you have. And can process the requests according to HTTP definitions.
A program that listens to any port is reachable from every computer in the same network. Ideally, it should be a known standard port (80 and 8080 for HTML servers; pick beyond 1024 for custom applications). It is even common practice to run development of a network reachable program on the same computer you are doing the development on.
If you can reach it via localhost, you can reach it from anywhere within the same network, and from anywhere else there is a path to this machine and its network adapter.
Caveat: A lot of all-in-one development environments in default installations limit access to Localhost. You do not want your admin tools reachable from the Internet, after all.
Hardware:
The hardware begins somewhere at "that 10-year-old computer that runs XP or Linux" and ends somewhere around "128 core, with 2 TiB RAM and 256 TiB of SSDs in a raid", with the DB running on a different server too. Web applications tend to be pleasingly parallelizable, so you can/have to up it even more with clusters of those servers. And Geocast. And distributed design. And a lot of other stuff. It entirely depends on what scale we are talking about.
The simplest web server you are likely to meet is the router you are using, btw. They all run a Web server for configuration purposes, hosted on a Linux (that is doing all the DHCP and NAT work).
Networking:
Having a path from other networks – including anywhere on the Internet – now that is a totally different story and a part even harder than programming the application. Between the NAT of your Router and carrier grade NAT, this stuff became really hard.
- You always have the option to buy a fixed IP address from your ISP, even as private person. As it indicates, that will likely cost extra. A DNS entry would be a quality of life thing.
- Back before Carrier Grade NAT, you could work with your Dynamic IP address and a DynDNS service. But with carrier grade NAT, you now have another uncontrollable NAT to overcome - maybe. Depends on your provider.
- The ultimate solution to traverse a kind of NAT, any number of layers is TCP/IP hole punching. All VPN solutions use it. As do Skype, TeamViewer and all the others. The problem is: In order to do TCP/IP hole punching, you need a server already reachable on the Internet.
- If it is about small scales (1 to 10 endpoints), usually, the simplest way is to just make a VPN connection into the network having the servers. Most Routers have support for it.
-
2"That 10 year old computer that runs Linux". Considering the age of the web, we can safely push that back. I personally recall running a webserver on an original Intel 80386, about 20 years ago.– MSaltersMar 14, 2017 at 13:17
-
@MSalters You can go much lower end than that. I can't find it today, but a few years ago I ran into a shell script/CGI web server that could be run on hardware as low ended as a moto 68k. It was apparently relatively popular 15-20 years ago in the embedded space. May 18, 2018 at 15:02
If you have on hand any kind of computer (PC, laptop, smartphone, raspberryPI...) with Python installed, just type:
$ python -m SimpleHTTPServer
Or if you have Node.js installed:
$ npm install http-server -g
$ http-server
Congratulation, you have a web server!