Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

It's much variants described in Internet how to display maintenance page with nginx. But I didn't find the solution to check if user is a developer and not to display maintenance page for developers.

I use try_files, which does't works as I need after any IF-section was entered. So I made my own solution, which I want to share. It works in any configuration with try_files, proxy and so on.

share|improve this question

1 Answer 1

up vote 1 down vote accepted
  1. In http section (out of any server section) check the user if he is a developer:

    map $http_cookie $isDevHack {
        default "";
        ~DEVELOPER_SECRET=1010 "/non-existed-location";
    }
    

    User is a developer if he had DEVELOPER_SECRET with 1010 value in this case. This map is shared for all servers in config.

  2. Append server section with 503-error handler:

    error_page 503 @maintenance;
    location @maintenance {
         rewrite ^(.*)$ /maintenance-mode.html break;
    }
    

    maintenane-mode.html is a page to display for non-developer users in maintenance mode. File path is relative to document_root of current server.

  3. In location sections, which must be protected in maintenance mode, add before any normal-mode rules:

    if (-f "$isDevHack/home/site-home/maintenance") {
        return 503;
    }
    

    If current user is a developer, checked file name will be prepended with /non-existed-location prefix and if will never be entered.

share|improve this answer

Your Answer

 
discard

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.