use strict; use HTTP::Daemon; use HTTP::Status; $SIG{PIPE}='go_away'; sub go_away { print "Broken Pipe detected\n" } my $html_docs = "/var/www/html"; open LOG, ">> webserver.log" or die "Unable to open log\n"; LOG->autoflush(1); my $d = HTTP::Daemon->new( LocalAddr => 'localhost', LocalPort => 8080, ) or die; print "Listening...\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { my $url = $r->url->path; print LOG "$url"; if ($r->method eq 'GET' and $r->url->path eq "/") { $c->send_file_response("$html_docs/index.html"); } elsif ($r->method eq 'GET') { $c->send_file_response("$html_docs$url"); } else { $c->send_error(RC_FORBIDDEN) } } $c->close; undef($c); }