althttpd部署hugo静态网站

之前都hugo网站都是用server命令直接跑,后来因为有加密需求,需要编译出静态网页托管到外部web服务器,刚开始想按教程用caddy或nginx,因为服务器上已经设置了frp反向代理了,caddy老是跑不通,突然想起来D. Richard Hipp大佬都althttpd服务器,够轻量好用,还要啥自行车。到官网Althttpd: The Althttpd Webserver下载源文件,运行命令编译:

gcc -Os -o /usr/bin/althttpd althttpd.c

不到一分钟,安装完了!一条命令服务器就跑起来了:

1
althttpd -root ~/www -port 8080

膜拜大佬中~

官网建议用xinetd来启动althttpd服务,并给出了sqllite.org网站都xinetd配置。xinetd咱也没用过,查了下我的ubuntu系统还没有这个软件。于是一通搜索学习了下:

(wiki原文:)In computer networking, xinetd (Extended Internet Service Daemon) is an open-source super-server daemon which runs on many Unix-like systems and manages Internet-based connectivity.

xinetd原来叫做扩展internet服务守护程序,一个运行在类Unix系统上,用来管理基于Internet连接的服务的开源超级服务守护程序。

之前用惯了systemd,这玩意怎么用呢,又是一通搜索,发现很多关于systemd和其他系统服务守护程序的争议,systemd 为什么会有那么大的争议?

原来用的比较习惯的systemd还有这段历史,查到一篇用systemd代替xinted进行配置都文章,systemd代替xinetd - 代码先锋网,感觉配置挺麻烦,确实没有xinted简洁优雅,不是hipp大佬都风格,于是还是回到xinted上,搜索学习一番,才知道xinted启动相应服务很简单,只要在/etc/xinetd.d/目录下放上相应都服务配置文件,然后重启xinted服务就行。首先sudo apt install xinted安装,套用althttpd官网上的配置文件,把-root参数对应都网站目录改成hugo的public目录,重启xinted服务:

1
sudo service xinetd restart

没反应,sudo service xinetd status 看不到输出,于是再次详细学习下xinetd相关知识,

https://en.wikipedia.org/wiki/XinetdXinetd服务的安装与配置详解 - 云+社区 - 腾讯云,原来要在配置文件里把"disable=no",服务才能启动,还有"type=UNLISTED" ,都加上,再次重启xinetd服务,访问绑定都althttpd端口,发现报错,说"/"目录下没有相关文件,说明web服务已经启动了,但是没有访问到相应目录。再次研读althttpd.md说明,发现这一段:

For each incoming HTTP request, althttpd takes the text of the Host: parameter in the request header, converts it to lowercase, and changes all characters other than ASCII alphanumerics into "_". The result determines which subdirectory to use for content. If nothing matches, the "default.website" directory is used as a fallback.

For example, if the Host parameter is "www.SQLite.org" then the name is translated into "www_sqlite_org.website" and that is the directory used to serve content. If the Host parameter is "fossil-scm.org" then the "fossil_scm_org.website" directory is used. Oftentimes, two or more names refer to the same website. For example, fossil-scm.org, www.fossil-scm.org, fossil-scm.com, and www.fossil-scm.com are all the same website. In that case, typically only one of the directories is a real directory and the others are symbolic links.

On a minimal installation that only hosts a single website, it suffices to have a single subdirectory named "default.website".

原来althttpd通过和域名对应的.website文件夹区分不同网站的目录,如果没有找到对应都目录则访问"default.website"目录,于是把hugo的public文件夹映射到default.website目录,再访问域名,成功了~

然后发现althttpd不支持中文urI

Any characters in the URI pathname other than [0-9a-zA-Z,-./:_~]

are converted into "_". This applies to the pathname only, not

to the query parameters or fragment.

杯具了,还是换回nginx吧,直接nginx的docker官方镜像,Docker Hub

1
$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
updatedupdated2021-11-122021-11-12