
Merecat最初是在Mongoose的双关语中,但现在可用于实际的Web服务目的。但是,这不是一个真正的Meerkat,而是另一个模仿猫,它是从Jef Poskanzer创建的Great Thttpd分配的。
Merecat HTTPD扩展了THTTPD最初提供的功能,但仍有一个有限的功能集:
.htpassd和.htaccess支持php-cgi (如果在merecat.conf中启用)由此产生的足迹(〜140 KIB)使其快速,适合小型和嵌入式系统!
Merecat可作为简化的2条BSD许可证的免费/开源软件提供。有关更多信息,请参见“手册” merecat(8)或FAQ。
其余的读数涵盖了一些基本功能和建议。有关更多深入的用例示例,请参见以下howtos:
尝试使用简单部署的Docker Merecat安全隔离。
要在您的~USERNAME/public_html/中保护目录,请使用随附的htpasswd工具创建文件.htpasswd :
user@example: ~ / > cd public_html/Downloads
user@example: ~ /public_html/Downloads/ > htpasswd -c .htpasswd friend
Changing password for user friend
New password: *****
Re-type new password: *****使用configure脚本启用此功能和用户主目录。在下面的“功能”部分中查看有关此信息的更多信息。
在服务器上设置虚拟主机可能与其他Web服务器有点麻烦。使用Merecat,您只需为Web Server root中的每个主机创建目录:
/var/www/
|-- icons/
|-- cgi-bin/
|-- errors/
| `-- err404.html
|-- ftp.example.com/
`- www.example.com/
edit /etc/merecat.conf :
virtual-host = true
cgi "/cgi-bin/*|**.cgi" {
enabled = true
}
现在,Web Server root, /var/www/不再提供文件,只有虚拟主机目录执行,在icons/ , cgi-bin/和errors/的共享文件中执行。
在Linux上,绑定安装座可用于设置FTP和Web访问相同文件。示例/etc/fstab :
/srv/ftp /var/www/ftp.example.com none defaults,bind 0 0
优化Web服务器的性能有很多技巧。最重要的之一是浏览器缓存。 Merecat支持ETag:和Cache-Control:但是要启用后者,您需要在/etc/merecat.conf中定义max-age设置:
max-age = 3600 # One hour
该值完全取决于站点。对于嵌入式系统,您可能需要将其设置为最大值,而对于其他情况,您可能需要其他东西。默认情况下,这将被禁用(0)。
另一个技巧是采用gzip压缩。 Merecat拥有为HTML,CSS和其他text/*文件提供内置支持,如果有同一文件的.gz版本。这是如何压缩相关文件的示例:
root@example: ~ / > cd /var/www/
root@example:/var/www/ > for file in ` find . -name ' *.html ' -o -name ' *.css ' ` ; do
gzip -c $file > $file .gz ; done这种方法比让Merecat即时“放气”文件更友好,否则它可以做到。
如果已安装了configure找到OpenSSL,则可以启用HTTPS支持,可以使用--without-ssl禁用。但是,要访问SSL/TLS设置,您还需要支持merecat.conf ,因此您必须安装LibConfuse。有关所有构建要求,请参见下文。
默认情况下,HTTPS支持具有SSLV2,SSLV3和TLSV1(硬编码)。只有TLSV2及以后才能按照客户端启用和协商。
要为HTTPS设置MERECAT,必须启用以下/etc/merecat.conf设置:
server secure {
port = 443
ssl {
certfile = /etc/letsencrypt/live/example.com/fullchain.pem
keyfile = /etc/letsencrypt/live/example.com/privkey.pem
dhfile = /etc/letsencrypt/live/example.com/dhparam.pem
}
}
Merecat完全支持我们的加密证书,包括HTTP-01续订。使用服务器位置指令:
server default {
port = 80
location "/.well-known/acme-challenge/**" {
path = "letsencrypt/.well-known/acme-challenge/"
}
redirect "/**" {
code = 301
location = "https://$host$request_uri$args"
}
}
该path必须相对于服务器根目录。使用绑定安装座获取/var/lib/letsencrypt进入服务器根。这样,我们可以确保certbot仅写入自己的目录,并且不能写入服务器根中的任何文件。
然后使用以下参数运行certbot ,然后添加您要支持Merecat的所有虚拟主机:
root@example:/var/www/ > certbot certonly --webroot --webroot-path /var/lib/letsencrypt如何看:
要创建一个自签名的证书并启用完美的前向保密,PFS,即Diffie-Helman参数(可选),请使用openssl工具,如下所示。请注意,大多数证书设置都在openssl.cnf中使用子壳,更重要的是注意到使用subjectAltName或san。当今大多数浏览器都需要后者。
root@example:/var/www/ > mkdir private certs
root@example:/var/www/ > openssl req -x509 -newkey rsa:4096 -nodes
-keyout private/server.key -new -out certs/server.pem
-subj /CN=www.acme.com -reqexts SAN -extensions SAN
-sha256 -days 3650 -config <( cat /etc/ssl/openssl.cnf
<( printf ' [SAN]nsubjectAltName=DNS:www.acme.com ' ) )
root@example:/var/www/ > openssl dhparam -out certs/dhparm.pem 4096对于具有两台服务器的设置,可以使用以下示例在端口4443上运行HTTP,端口8080上的HTTP,并在任何访问上重定向到HTTPS服务器:
server secure {
port = 4443
ssl {
certfile = certs/server.pem
keyfile = private/server.key
dhfile = certs/dhparm.pem
}
}
server default {
port = 8080
redirect "/**" {
code = 303
location = "https://$host:4443$request_uri$args"
}
}
支持的HTTP重定向代码为:301、302、303和307。
位置设置支持三个NGINX样式变量,如示例所示。请注意围绕模式的引号,或者.conf解析器会认为该模式是C风格的评论。
Merecat取决于一些外部库,如果启用了,例如OpenSSL,Zlib和LibConfuse。在Debian/Ubuntu系统上,您可以使用以下方式安装依赖项:
user@example: ~ / > sudo apt install pkg-config libconfuse-dev libssl-dev zlib1g-dev如果您构建deps。从源来看,他们可能默认使用/usr/local的安装前缀。非debian/ubuntu系统很少支持此GNU标准,因此,您将其引用Merecat configure脚本:
user@example: ~ /merecat/ > PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig ./configure在不支持/etc/merecat.conf的情况下构建Merecat:
user@example: ~ /merecat/ > ./configure --without-config如果您从git来源建造而不是发布的tarball,请记住:
user@example: ~ /merecat/ > ./autogen.sh要将httpd安装到/usr/sbin/ ,将默认索引和图标安装到/var/www中,然后配置文件到/etc/merecat.conf :
user@example: ~ /merecat/ > ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
user@example: ~ /merecat/ > make
user@example: ~ /merecat/ > sudo make install通过将--host标志设置为配置脚本,可以为另一个目标进行交叉编译Merecat。 GNU文档中有很好的记录。注意:通常会自动检测到--build系统。
默认情况下,Merecat构建是无声的。对于详细的编译器输出,禁用使用
configure --disable-silent-rules,或用make V=1构建。
Merecat由前端merecat.c和独立的HTTP库libhttpd.c组成,可以以各种方式调整该库,并在需要时将其嵌入Web服务器(如果需要)。
最常见的选项可从merecat命令行和merecat.conf配置文件获得。可以使用configure脚本启用其他较不常见的选项:
--enable-builtin-icons Enable built-in icons for dir listings
--enable-htaccess Enable .htaccess files for access control
--enable-htpasswd Enable .htpasswd files for authentication
--enable-public-html Enable $HOME/public_html as ~USERNAME/
--enable-msie-padding Add padding to error messages for Internet Explorer
--disable-dirlisting Disable directory listings when no index file is found
--without-config Disable /etc/merecat.conf support using libConfuse
--without-ssl Disable HTTPS support, default: enabled
--without-symlinks Disable httpd and in.httpd symlinks to merecat
--without-zlib Disable mod_deflate (gzip) using zlib
源文件merecat.h具有更多可以调整的功能,其中一些在MAN页面中提到,但是标头文件也具有非常有用的注释。
Merecat是STHTTPD的叉叉,在网络周围发现了许多丢失的补丁。 STHTTPD项目依次是原始THTTPD的叉子-Tiny/Turbo/Throttling HTTP服务器。