Skip to content

Instantly share code, notes, and snippets.

@oakhole
Created August 18, 2015 05:02
Show Gist options
  • Save oakhole/36d2eb60c3d03bf9f536 to your computer and use it in GitHub Desktop.
Save oakhole/36d2eb60c3d03bf9f536 to your computer and use it in GitHub Desktop.
利用 inetd 实现web server
#!/bin/bash
base=/var/www
read request
while /bin/true; do
read header
[ "$header" == $'\r' ] && break;
done
url="${request#POST }"
url="${url% HTTP/*}"
filename="$base$url"
if [ -f "$filename" ]; then
echo -e "HTTP/1.1 200 OK\r"
echo -e "Content-Type: `/usr/bin/file -bi \"$filename\"`\r"
echo -e "\r"
cat "$filename"
echo -e "\r"
else
echo -e "HTTP/1.1 404 Not Found\r"
echo -e "Content-Type: text/html\r"
echo -e "\r"
echo -e "404 Not Found\r"
echo -e "Not Found
The requested resource was not found\r"
echo -e "\r"
fi
# www stream tcp nowait nobody /usr/local/bin/webd webd
# /etc/init.d/inetd restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment