💾 Archived View for r.bdr.sh › nginx_office_hours.gmi captured on 2024-07-08 at 23:44:10. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-03-21)

-=-=-=-=-=-=-

NGINX Office Hours Module

Or ngx_http_office_hours_filter_module for short, it's a module for nginx that lets you specify a schedule and only serve content during that time.

view source @ git.r.bdr.sh

source mirror @ sourcehut

Install

From Source

You can install it from source:

1. Clone nginx source to a directory

2. Clone ngx_http_office_hours_filter_module to another directory

3. Build NGINX as you usually would[1], appending the option for this dynamic module:

./configure --add-dynamic-module=/path/to/ngx_http_office_hours_filter_module
make
sudo make install

[1] Compiling And Installing NGINX from Source

The office_hours directive

The office_hours directive expects a list of time ranges separated by spaces in the format: "HH:mm-HH:mm". The hours should be in 24 hour format, and the minutes are optional. The word "closed" can be used to indicate that the server is not operating on that day.

The first range will be used as the default value, and the rest will be read from right to left, starting with sunday.

When the current time is within those hours, the server will operate as usual, otherwise it will return a 403 with a page showing the operating hours of the service. See this example for a page that's always closed[2]

[2] A page that is never open.

Example 1: Open 24 hours

Don't use this directive.

Example 2: Open every day from 08:30 AM to 7:00 PM

location / {
  office_hours 8:30-19;
}

Example 3: Open monday to saturday from 08:30 AM to 7:00 PM, but closed sundays

location / {
  office_hours 8:30-19 closed;
}

Example 4: Open weekdays from 08:30 AM to 7:00 PM, Saturdays 10:00 AM to 4:00 PM, closed on sundays

location / {
  office_hours 8:30-19 10-16 closed;
}

Example 5: Open weekdays from 08:30 AM to 7:00 PM, closed on thursdays, reduced hours on weekends.

location / {
  office_hours 8:30-19 closed 8:30-19 10-16 10-16;
}

Example 6: Closed every day.

Uninstall nginx.

The office_hours_additional_information directive

With this directive you can specify additional information for when the server is closed, such as contact information or alternate locations for the data. It accepts a text containing HTML that will be injected to the body of the office hours page.

location / {
  office_hours_additional_information "<h1>Additional Information></h1>
    <p>Please do not email us asking to open the website 24/7. Send all complaints to friendship.quest/@ruben</p>"
}