Created
August 18, 2015 05:02
-
-
Save oakhole/36d2eb60c3d03bf9f536 to your computer and use it in GitHub Desktop.
利用 inetd 实现web server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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