我正在使用以下命令运行 busybox httpd:
busybox httpd -p 80 -h /var/www
它可以工作,但是我需要将缓存控制标头设置为无缓存。
目前我的服务器仅附加这些标题:
HTTP/1.0 200 OK
Content-type: text/html
Date: Thu, 28 Jun 2018 06:58:08 GMT
Connection: close
Accept-Ranges: bytes
Last-Modified: Thu, 28 Jun 2018 06:57:43 GMT
Content-Length: 45
我如何配置我的busybox httpd服务器以附加
Cache-Control: no-cache
标题?
答案1
BusyBox HTTP Daemon (httpd) webserver 是一个自己的简单 web 服务器实现,没有广泛的配置选项,正如你从OpenWRT配置文档或来自的评论块httpd.c
来源(第 39-60 行):
* httpd.conf has the following format:
*
* H:/serverroot # define the server root. It will override -h
* A:172.20. # Allow address from 172.20.0.0/16
* A:10.0.0.0/25 # Allow any address from 10.0.0.0-10.0.0.127
* A:10.0.0.0/255.255.255.128 # Allow any address that previous set
* A:127.0.0.1 # Allow local loopback connections
* D:* # Deny from other IP connections
* E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
* I:index.html # Show index.html when a directory is requested
*
* P:/url:[http://]hostname[:port]/new/path
* # When /urlXXXXXX is requested, reverse proxy
* # it to http://hostname[:port]/new/pathXXXXXX
*
* /cgi-bin:foo:bar # Require user foo, pwd bar on urls starting with /cgi-bin/
* /adm:admin:setup # Require user admin, pwd setup on urls starting with /adm/
* /adm:toor:PaSsWd # or user toor, pwd PaSsWd on urls starting with /adm/
* /adm:root:* # or user root, pwd from /etc/passwd on urls starting with /adm/
* /wiki:*:* # or any user from /etc/passwd with according pwd on urls...
* .au:audio/basic # additional mime type for audio.au files
* *.php:/path/php # run xxx.php through an interpreter
使用 BusyBox HTTPd 的选项:
答案2
docker run -d --name busybox-http -p 8080:8080 -e TZ=UTC-8 busybox sh -c "
echo GMT-8 > /etc/TZ
mkdir -p /root/cgi-bin
cat > /root/cgi-bin/a.html <<EOF
#!/bin/sh
echo -e 'Content-Type: text/plain\n'
echo \"hostname=[\\\$(hostname)], time=[\\\$(date '+%F %T')], query=[\\\${QUERY_STRING}], path=[\\\${PATH_INFO}]\"
echo \"requestUrl=[\\\${REQUEST_URI}]\"
echo -e \"\n=== env list:\n\\\$(env|sed 's/\n/<br>/g')\"
EOF
chmod u+x /root/cgi-bin/a.html
httpd -p 8081 -h /root
cat > /root/httpd.conf <<EOF
P:/:http://localhost:8081/cgi-bin/a.html/
EOF
httpd -p 8080 -c /root/httpd.conf
sleep infinty
"
curl localhost:8080/a/b?c=1
结果输出:
hostname=[e95c54e5ff19], time=[2021-01-19 23:20:42], query=[c=1], path=[/a/b]
requestUrl=[/cgi-bin/a.html/a/b?c=1]
=== env list:
GATEWAY_INTERFACE=CGI/1.1
HOSTNAME=e95c54e5ff19
SHLVL=2
REMOTE_ADDR=[::ffff:127.0.0.1]
HOME=/root
QUERY_STRING=c=1
HTTP_USER_AGENT=curl/7.29.0
REMOTE_PORT=51456
HTTP_ACCEPT=*/*
SCRIPT_FILENAME=/root/cgi-bin/a.html
HTTP_HOST=localhost:8080
REQUEST_URI=/cgi-bin/a.html/a/b?c=1
SERVER_SOFTWARE=busybox httpd/1.31.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SERVER_PROTOCOL=HTTP/1.0
PATH_INFO=/a/b
REQUEST_METHOD=GET
PWD=/root/cgi-bin
SCRIPT_NAME=/cgi-bin/a.html