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?
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.
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.
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.
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.
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).
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.
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!