Web server in one line of bash
razvantudorica.com
razvantudorica.com
Python 2.x:
python -m SimpleHTTPServer
Python 3.x:
python -m http.server 8000 twistd --nodaemon web --path=. -c snakeoil.crt -k snakeoil.key --https=8443
And to generate a 100-year localhost key/cert for use with this: openssl genrsa -passout pass:dummy -out snakeoil.secure.key 1024
openssl rsa -passin pass:dummy -in snakeoil.secure.key -out snakeoil.key
openssl req -new -subj "/commonName=localhost" -key snakeoil.key -out snakeoil.csr
openssl x509 -req -days 36500 -in snakeoil.csr -signkey snakeoil.key -out snakeoil.crt cat /etc/certs/ssl-cert-snakeoil.pem \
/etc/priv/ssl-cert-snakeoil.key >> \
/etc/priv/ssl-cert-and-key-snakeoil.pem
chmod og-rwx /etc/priv/ssl-cert-and-key-snakeoil.pem
#note instructions above on how to generate a fresh
#self-signed cert
python3 -m http.server 8000 &
stunnel -p /etc/ssl/private/ssl-cert-and-key-snakeoil.pem -r 8000 -d 4430
Which does require stunnel, in addition to python, obviously. rm snakeoil.secure.key snakeoil.csrWeb speech API: http://updates.html5rocks.com/2013/01/Voice-Driven-Web-Apps-...
while true; sudo /usr/sbin/apachectl start; break; done;
while true; do sudo /usr/sbin/apachectl start; break; done;netcat's cool, but the post could've gone a bit further. If it's an intro "how to do this", maybe explain the moving parts for beginners?
Unless the specified 'index.html' is only readable by root, you don't have to be root to run that.
Only the low ports are restricted from regular users.
on server: while true; nc -l $PORT < $FILE; done
on client: nc $SERVER $PORT > $FILE
Quick, simple and easy to fire up. You can continue to hack on the file and nc will serve up the latest saved version. $ goe 'net/http' 'ListenAndServe(":8080", FileServer(Dir("/usr/share/doc/")))'
[1] https://github.com/shurcooL/goe socat TCP-LISTEN:8080,fork,crnl SYSTEM:'printf \"HTTP/1.1 200 OK\\n\\n\"\; cat test.html'
The extra quoting you need to do the the SYSTEM argument makes this rather cumbersome. socat is a powerful tool, but can sometimes be a pain to use.Here's one use I found for it recently, when I wanted to do some experimentation with multicast:
socat - UDP-DATAGRAM:239.255.1.1:4242,ip-add-membership=239.255.1.1:10.0.0.10,ip-multicast-loop=0,bind=:4242
This causes socat to bind to the multicast group 239.255.1.1 on the interface that has the unicast IP 10.0.0.10, sending and receiving on port 4242 over UDP, reading from stdin and writing to stdout. It basically gives you a simple chat service over the local network.Works even in an initramfs, and in some embedded systems. Serves up the current directory, and you can even have CGI scripts in cgi-bin.
* Side note: if it is, make sure your router manufacturer provides the GPL source release.
$ curl localhost:8080 & curl localhost:8080
<!doctype html>
[...]
curl: (7) Failed connect to localhost:8080; Connection refused
Yes, the server "restarts" after each request, and during the restart, it's not listening.That's not what I would call a "server".
npm install -g node-static
# serve up the current directory
$ static
serving "." at http://127.0.0.1:8080
More at https://github.com/cloudhead/node-static php -S 127.0.0.1:8080http://stackoverflow.com/questions/3940046/can-i-use-netcat-... seems to have a basic example.
ruby -run -e httpd . -p 5000
twistd web --path . --port 8080 npm install -g serve
serveCould be an OS-dependent thing. I'm using OS X.
int_cmd(){exit 1;}trap 'int_cmd' 2;