Q:

Deliver a 503 Service Unavailable at specific times

How can I configure nginx to deliver a "503 Service Unavailable" every day from 3am to 4am?

A:

And yet, it's so much simpler to just check for a maintenance flag.
location / {
    if( -f $document_root/maintenance.flag ) {
        return 503;
    }
}

Now when you do the maintenance, which I presume is run by cron you create the file and when done clean up after yourself. It has the added advantage, that you can create that file also for unscheduled maintenance.

A:

The SSI Module has a variable called $date_gmt that you get the time out of. A few if statements with that variable might be able to help.
Alternatively, you can write something in Lua by compiling in HTTPLuModule. Lua will provide you with a lot more flexibility doing more complicated stuff in Nginx. The downside is you'd have compile the module in.
I haven't tested this code, but something like it will might help get you started.
location ~ / {
    set_by_lua $between_three_and_four '
        local time = os.date("*t")
        local between_three_and_four = false

        if time.hour == 3 then
            between_three_and_four = true
        end

        return between_three_and_four
    '

    if ($between_three_and_four) {
        return 503;
    }
}

