Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wondering how I send back a HTTP response of 501 (Not Implemented) in Lighttpd web server, when somebody tries to access our over non-ssl.

The check we have, but don't see how to actually send back the HTTP response of 501.

$HTTP["host"] =~ "api\.mydomain\.com$" {
        $HTTP["scheme"] == "http" {
                //// HOW DO WE SEND BACK HTTP RESPONSE 501
share|improve this question

The lighttpd way:

With config file, I only know about 404 errors. To send a "non implemented" response, you may use lighttpd mod Magnet (and install LUA), then:

In the config file:

$HTTP["host"] =~ "api\.mydomain\.com$" {
        $HTTP["scheme"] == "http" {
            magnet.attract-physical-path-to = ("/path/to/501.lua")

Note that "/path/to/501.lua" should be readable by lighttpd. Then in the 501.lua file:

lighty.content = { { filename = "/path-to-your/501.html" } }
lighty.header["Content-Type"] = "text/html" 
return 501

Very hard to just send a 501... right ?

The alternative way:

If you already have a dinamic language pluged with fastcgi, etc, you can implement error responses (lets say, 501.php) that does what the .lua script makes:

  • Send the proper http response (feasible on any "web" language)
  • Print the proper headers (feasible on any "web" language)
  • Print the proper html or template or static file (feasible on any "web" language)

And use them where needed.

share|improve this answer
Ok, how about this, instead of returning 501, how do we just kill that request. Basically, I don't want users to be able to hit in non-ssl. Is there a way to just abort the HTTP request in lighttpd? – Justin Apr 9 '11 at 19:55
try adding: url.access-deny = ("") where your comment "//// HOW DO WE SEND..." – poisonbit Apr 10 '11 at 9:11
Yeah, that returns back 403, Forbidden. I suppose that works, anything to just drop the connection though, basically just server not found error. – Justin Apr 10 '11 at 20:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.