What makes a PC able to be a web server and what makes it unable?

44

13

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?

VincentTheonardo

Posted 2017-03-13T04:05:15.807

Reputation: 543

A network card. – el.pescado – 2017-03-16T06:26:41.800

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. – user3528438 – 2017-03-16T13:02:15.807

@el.pescado Unless the client is on the same host. – Dmitry Grigoryev – 2017-03-16T14:44:11.893

Answers

96

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.

davidgo

Posted 2017-03-13T04:05:15.807

Reputation: 49 152

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 – phuclv – 2017-03-13T08:24:49.153

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. – davidgo – 2017-03-13T08:53:01.737

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. – Bob – 2017-03-13T12:31:15.557

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. – Luaan – 2017-03-13T12:50:02.213

Near the end of your first paragraph, you say "...in practice, any device can act as a web server." when what it seems like you meant is "... in theory, any device can act as a web server.". Definitely not important in the grand scheme of the answer, just a little nitpick. – JMac – 2017-03-13T15:23:33.120

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. – Peter - Reinstate Monica – 2017-03-13T16:40:28.297

1My laptop runs nearly 24/7, and I believe that plenty of things there are more sensitive to "bit rot" than a tiny script that handles HTTP requests is. Also note that the most interesting stuff that a web server can provide is stored on a hard drive so that it's not lost when the server unexpectedly powers down (also because RAM is small). – John Dvorak – 2017-03-13T19:36:14.747

@JanDvorak "RAM is small" - I had a computer 20 years ago with 10 times less hard drive space than I have RAM now. – user253751 – 2017-03-13T21:31:30.627

You don't need to have networking and other machines to access it. For example, you can set a very real apache web server and even have many instances of different clients like firefox, chrome, vivaldi etc. all running on the same machine. – Džuris – 2017-03-14T11:14:49.860

Roku devices actually communicate over the network - you can control it with HTTP requests. – Wayne Werner – 2017-03-14T17:02:53.607

25

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.

enter image description here

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.

Journeyman Geek

Posted 2017-03-13T04:05:15.807

Reputation: 119 122

11

It is even possible to solder together some TTL chips and run a webserver. See this webpage for the details

– Josef says Reinstate Monica – 2017-03-13T08:36:48.480

7That's roughly like saying "Its even possible to bolt together some steel and build the Eiffel tower. That's so cool – Journeyman Geek – 2017-03-13T09:04:33.080

It could even assume any TCP connection to mean a valid request, and send a HTTP response disregarding any input :) – rackandboneman – 2017-03-13T09:27:00.690

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!). – djsmiley2k TMW – 2017-03-13T11:58:23.583

I was scrolling down to look for the ESP, so I know what it is. However, for those who don't, it might be good to add a note that it is a "minimal microcontroller with wifi". – Jasper – 2017-03-13T13:26:44.650

I'm currently running a web server on a Raspberry Pi. – Charles Burge – 2017-03-13T18:07:44.040

5@djsmiley2k Eclipse help uses a local webserver. Because Java. – user253751 – 2017-03-13T21:32:51.703

What in the world is that wooden thing in the GIF? – Oscar Bravo – 2017-03-14T11:26:39.410

1It's a most useless machine – Journeyman Geek – 2017-03-14T11:31:34.317

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. – rackandboneman – 2017-03-14T13:12:05.280

To explain the "hilariously inefficient": Even nowadays, HTML generating applications are very often set up in a way that they completely initialize a new environment for each and every request - very safe if your programmers care only about making work what should work and not also making sure that what shouldn't work doesn't work (security), but creating a boatload of overhead. – rackandboneman – 2017-03-14T13:16:14.823

My issues with the rpi are less about power and somewhat more about reliability. That's a different question though. – Journeyman Geek – 2017-03-14T23:00:54.520

1

@rackandboneman That's actually not so true now... it was true for CGI (about... two decades ago?), but most modern server-side frameworks will persist the application process. See, for example, FastCGI (used for PHP, etc.), and of course frameworks like ASP.NET (reuses the application pool, and even the appdomain), JavaEE, etc.. By and large, security-related isolation has been moved inside the processes and often dropped altogether for managed languages.

– Bob – 2017-03-14T23:37:04.523

Of course. And a great many PHP setups do not take advantage of it, or do it in a way that while the PHP interpreter persists, the application context with all its initialization overhead does not. And I guess a lot of app software is still written in a way that truly reusing an application context would indeed create massive security problems. – rackandboneman – 2017-03-15T09:03:35.080

11

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:

Without these, all you have is a potential web server.

user477799

Posted 2017-03-13T04:05:15.807

Reputation:

._. 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 – 2017-03-13T06:50:02.137

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. – davidgo – 2017-03-13T08:58:36.663

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. – rackandboneman – 2017-03-13T09:30:58.027

@rackandboneman Very well. I will clarify the meaning of "if your operation gets bigger" to address your concern. – None – 2017-03-13T09:37:07.577

@rackandboneman Not just 'could be' made to handle, but 'often was'. – jwg – 2017-03-13T09:42:39.873

"1 Gbit/sec Ethernet or 802.11g Wi-Fi" You do realize that 802.11g Wi-Fi is about 20 times slower than gigabit ethernet? – Zeb McCorkle – 2017-03-15T19:50:01.403

@ZebMcCorkle I do. But a 54 MB/sec Ethernet standard does not exist. And procuring 100 MB/sec Ethernet might be a problem. Let's keep things practical, shall we? – None – 2017-03-16T02:20:29.767

@JourneymanGeek : Such rhetoric is not sensible without context. The Raspberry Pi can run "server" software (as defined by RFC 2616 (HTTP) Page 8) and respond to requests. There's no technical definition I know of to consider it to be a non-server, except that it may not fit some undefined perspectives. You could say the Raspberry Pi is not commercially-suitable Enterprise-grade "server-class" hardware, and that would be much more meaningful, and look much less wrong. Keep in mind many actually-useful web servers don't need to meet that criteria

– TOOGAM – 2017-03-16T07:58:59.380

@FleetCommand 802.11ac Wi-Fi is 1.3Gbps, much closer to the 1Gbps Ethernet. – Zeb McCorkle – 2017-03-17T00:56:18.137

@Zeb McCorkle But 802.11g is enough. Like I said let's keep things practical. The criteria here is commodity hardware with a good performance history, not two numbers being equal just for the kick of it. – None – 2017-03-17T08:00:12.860

8

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.

Christopher

Posted 2017-03-13T04:05:15.807

Reputation: 191

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. – MSalters – 2017-03-14T13:17:24.787

@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. – Dan is Fiddling by Firelight – 2018-05-18T15:02:25.590

3

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!

matt

Posted 2017-03-13T04:05:15.807

Reputation: 139