六款小巧的HTTP Server[C语言]

姜振濂
2023-12-01

1、micro_httpd - really small HTTP server
特点:
支持安全的 .. 上级目录过滤
支持通用的MIME类型
支持简单的目录
支持目录列表
支持使用 index.html 作为首页
Trailing-slash redirection
程序总共代码才200多行
这个httpd适合学习简单的Web Server编写学习,因为它只有一个简单的框架,只能够处理简单的静态页,可以考虑用来放静态页。
官方地址:http://www.acme.com/software/micro_httpd/
下载地址:http://www.acme.com/software/micro_httpd/micro_httpd_12dec2005.tar.gz

2、mini_httpd - small HTTP server 
特点:
支持GET、HEAD、POST方法
支持CGI功能
支持基本的验证功能
支持安全 .. 上级目录功能
支持通用的MIME类型
支持目录列表功能
支持使用 index.html, index.htm, index.cgi 作为首页
支持多个根目录的虚拟主机
支持标准日志记录
支持自定义错误页
Trailing-slash redirection
mini_httpd 也是相对比较适合学习使用,大体实现了一个Web Server的功能,支持静态页和CGI,能够用来放置一些个人简单的东西,不适宜投入生产使用。
官方地址:http://www.acme.com/software/thttpd/
下载地址:http://www.acme.com/software/mini_httpd/mini_httpd-1.19.tar.gz

3、thttpd - tiny/turbo/throttling HTTP server 
thttpd中是一个简单,小型,轻便,快速和安全的http服务器:
简单:它能够支持HTTP/1.1协议标准,或者超过了最低水平
小巧:它具有非常少的运行时间,因为它不fork子进程来接受新请求,并且非常谨慎的分配内存(性能对比表:http://www.acme.com/software/thttpd/benchmarks.html)
便携:它能够在大部分的类Unix系统上运行,包括FreeBSD, SunOS 4, Solaris 2, BSD/OS, Linux, OSF等等
快速:它的速度要超过主流的Web服务器(Apache, NCSA, Netscape),在高负载情况下,它要快的多
安全:它努力的保护主机不受到攻击,不中断服务器

thttpd 类似于lighttpd,对于并发请求不使用fork()来派生子进程处理,而是采用多路复用(Multiplex)技术来实现。因此效能很好。同时它还有一个特点就是基于URL的文件流量限制,这对于下载的流量控制而言是非常方便的。象Apache就必须使用插件实现,效率较thttpd低。
thttpd跟lighttpd类似,适合静态资源类的服务,比如图片、资源文件、静态HTML等等的应用,性能应该比较好,同时也适合简单的CGI应用的场合。
官方地址:http://www.acme.com/software/thttpd/
下载地址:http://www.acme.com/software/thttpd/thttpd-2.25b.tar.gz

4、lighttpd - light footprint + httpd = LightTPD 
Lighttpd是一个德国人领导的开源软件,其根本的目的是提供一个专门针对高性能网站,安全、快速、兼容性好并且灵活的web server环境。具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点。
lighttpd 是众多OpenSource轻量级的web server中较为优秀的一个。支持FastCGI, CGI, Auth, 输出压缩(output compress), URL重写, Alias等重要功能,而Apache之所以流行,很大程度也是因为功能丰富,在lighttpd上很多功能都有相应的实现了,这点对于apache的用户是非常重要的,因为迁移到lighttpd就必须面对这些问题。
实用起来lighttpd确实非常不错,apache主要的问题是密集并发下,不断的fork()和切换,以及较高(相对于 lighttpd而言)的内存占用,使系统的资源几尽枯竭。而lighttpd采用了Multiplex技术,代码经过优化,体积非常小,资源占用很低,而且反应速度相当快。
利用apache的rewrite技术,将繁重的cgi/fastcgi任务交给lighttpd来完成,充分利用两者的优点,现在那台服务器的负载下降了一个数量级,而且反应速度也提高了一个甚至是2个数量级!
lighttpd 适合静态资源类的服务,比如图片、资源文件、静态HTML等等的应用,性能应该比较好,同时也适合简单的CGI应用的场合。

官方地址:http://www.lighttpd.net/
下载地址:http://www.lighttpd.net/download/lighttpd-1.4.16.tar.gz

5、SHTTPD - Simple HTTPD
Shttpd是另一个轻量级的web server,具有比thttpd更丰富的功能特性,支持CGI, SSL, cookie, MD5认证, 还能嵌入(embedded)到现有的软件里。最有意思的是不需要配置文件!由于shttpd可以嵌入其他软件,因此可以非常容易的开发嵌入式系统的web server,官方网站上称shttpd如果使用uclibc/dielibc(libc的简化子集)则开销将非常非常低。

特点:
小巧、快速、不膨胀、无需安装、简单的40KB的exe文件,随意运行
支持GET, POST, HEAD, PUT, DELETE 等方法
支持CGI, SSL, SSI, MD5验证, resumed download, aliases, inetd模式运行
标准日志格式
非常简单整洁的嵌入式API
dietlibc friendly. NOT that friendly to the uClibc (*)
容易定制运行在任意平台:Windows, QNX, RTEMS, UNIX (*BSD, Solaris, Linux)
由于shttpd可以轻松嵌入其他程序里,因此shttpd是较为理想的web server开发原形,开发人员可以基于shttpd开发出自己的webserver!
官方网站:http://shttpd.sourceforge.net/
下载地址:http://jaist.dl.sourceforge.net/sourceforge/shttpd/shttpd-1.38.tar.gz

6、tinyhttpd

 

tinyhttpd is a very simple webserver. It is not for production use; instead it is primarily for a learning tool for persons investigating the http protocol and UNIX system calls.

Despite its simple nature, tinyhttpd supports threading and CGI scripts! For more information, see the accompanying README file and the code itself.

tinyhttpd is tested on Sparc Solaris and will probably not run on other operating systems as-is. However, commenting out the line that does threading may be all that is required to port it. I would like to autoconfiscate tinyhttpd at some point in time to help make it more portable.

There is no downloadable release of tinyhttpd, yet. Until then, you can get it by anonymous CVS.

The real homepage for tinyhttpd is the project page

地址:http://tinyhttpd.sourceforge.net/

转载自:http://blog.linuxphp.org/?action=show&id=60

【译】几种Web服务器比较

注意到有这款服务器nginx。没听过,一查有了下文。其中有一个还是听过的。对照翻译了下文。

Apache and IIS are the most common web servers in use today, but they are far from alone. There is a huge amount of web server software out there, both free and commercial.

到目前,Apache和IIS是用的最为普遍的Web服务器,但是它们太过单一,在此之外这里还有许多Web服务器软件,或是免费的或是商业的。

In this article we present four popular alternative web servers: Lighttpd, Nginx, LiteSpeed and Zeus. The first two are free and open source while the other two are commercial, closed-source alternatives. What they all have in common is that they focus on high performance.

本文我们介绍四种最受欢迎的Web服务器: Lighttpd, Nginx, LiteSpeed 和 Zeus。 前两个都是免费且开源的,而另两种都是商业的,闭源的。它们的共同点在于都着重于高性能上。

We will also take a look at how many websites are actually using these web servers.

我们看看有多少网站实际上在使用它们。

But first a brief presentation of each of one:

首先一个简短的介绍其中之一:

Lighttpd
Brief info: Pronounced “Lighty”, Lighttpd is as the name implies a small, lightweight web server which has a low memory footprint and light CPU load. Lighttpd is a good alternative to serve static content but it has also gained recognition in the Ruby on Rails and PHP communities.

Lighttpd 的名称暗示小,轻量级web服务器,占用内存小且cpu负荷低。Lighttpd 是服务于静态内容的不错选择。然而它更被公认为是用在Ruby 和 PHP 上。
Used by: Wikimedia (Wikipedia), Sourceforge, YouTube, The Pirate Bay, Meebo, Imageshack, Sendspace, Mininova.
Cost: Free
Open Source: Yes
OS platforms: Linux, freeBSD, Solaris, MacOS X, Windows (under Cygwin)
Homepage: http://www.oschina.net/p/lighttpd
Nginx
Brief info: Pronounced “engine X”, Nginx is a lightweight web server and reverse proxy. originally written by Igor Sysoev for Rambler.ru (Russia’s second most visited website). Nginx is known for stability and simple configuration in addition to its low resource consumption. It can also act as an IMAP/POP3 proxy.

Nginx 是一款轻量级web服务器和反向代理。最初由Igor Sysoev 编写。它的出名在于其稳定性和简单的配置,除此之外低资源消耗。 还有它可以作为IMAP/POP3协议。
Used by: Yellow Pages, Hulu, Zimbra, the Friends for Sale Facebook app, Rambler, and it also seems that Wordpress.com just started using it instead of LiteSpeed.
Cost: Free
Open Source: Yes
OS platforms: Linux, FreeBSD, Solaris, MacOS X
Homepage: http://www.oschina.net/p/nginx
LiteSpeed
Brief info: LiteSpeed is a commercial web server designed specifically for large websites. One of LiteSpeed’s advantages is that it can read Apache configurations directly which makes it easy to integrate with existing products to replace Apache. The server is lightweight and as the name implies very fast.

LiteSpeed 一种被特别设计用作大型网站的商业web服务器。 其中一个优势就是它能直接读取Apache 的配置信息。并轻易将它现有的产品结合在一起来代替Apache 。这种服务器是轻量级的就如它的名字暗示出非常快。
Used by: Wordpress (until recently at least, but now Wordpress.com appears to be using nginx), Twitter, GigaOm, Bravenet.
Cost: Free to $1,299 depending on the edition.
Open Source: No
OS platforms: Linux, FreeBSD, Solaris, MacOS X
Homepage: http://www.ruanku.com/p/litespeedtech-web-server
Zeus
Brief info: Zeus web server is a high performance web server. It has received PC Magazine Editors’ Choice award and also the eWeek/PC Magazine Innovation in Infrastructure award. Zeus is a highly flexible enterprise product.

Zeus web server 是一个高性能的web服务器。它曾被PC Magazine Editors’ Choice 授过奖并且eWeek/PC Magazine Innovation 也授予过它奖项。Zeus 是一种高度灵活的企业产品。
Used by: Sony, Telefónica, Virgin media, phpBB.
Cost: $1,700 up to two physical CPUs; $850 per additional CPU.
Open Source: No
OS platforms: Linux, FreeBSD, Solaris, HP-UX
Homepage: http://www.ruanku.com/p/zeus-web-server
How many websites are using these web servers?
According to Netcraft, Lighttpd is currently the most common of these four web servers. On April 1, the numbers of websites for each were as follows:
有多少网站在使用它们?
根据Netcraft统计,Lighttpd 是当前这四种服务器中最普遍的。在4月1日统计到的网站数字。

Lighttpd: 1,495,308
Nginx: 1,018,503
LiteSpeed: 668,030
Zeus: 420,477

These positions were not always the same, though. As you can see by the following graph, which shows the numbers from January 2006 to April 2008, the situation has changed significantly over time.

然而这个形势并不一直是一样的。通过下图你可以看到从2006年1月到2008年4月,形势随着时间而改变着。


The graph is based on data from Netcraft (their web server survey archives).

The huge leap for Lighttpd in January-March of 2007 is most likely due to one or more web hosting or domain registration companies switching over to Lighttpd either for their regular pages, or for parked pages, or both. If anyone knows what happened there in more detail, please feel free to let us know in the comments.

2007年1月到3月,很可能归咎于一个或多个web服务商或域名注册公司转变使用Lighttpd 。发生了什么如果有人知道的更详细些……

Interestingly, the number of servers using the Zeus web server has remained quite constant over the last two years, and even decreased a little. That said, it is mainly an enterprise solution, so this is perhaps not so surprising.

非常有趣的是,过去两年使用Zeus 作为服务器的数量维持在一个非常恒定的状态。而且减少了一点点。可以说,它主要是针对企业解决方案。所以从这点上是不值得惊讶的。

The two web servers that have been growing the fastest lately are Nginx and LiteSpeed. Nginx recently passed the one-million-websites mark.

Nginx 和 LiteSpeed 这两种服务器增长速度很快。近来Nginx 已经超过了一百万个站点

These numbers of course still pale next to Apache’s roughly 83 million websites, but there is no doubt that these alternative web servers are gaining in popularity. Who knows, one of them may be just right for you?

当然这些数字对于Apache的大概8300万来说不值一提。但仍无置疑的是这些可供选择的服务器越来越受欢迎。有谁知道,其中之一很可能是非常适合你的?

 类似资料: