Solved: Nginx running in a Dokku hosted app returns unknown directive "auth_basic"


In [163]:
# <ignore> start meta code for Jupyter notebook blog 
from importlib import reload
from pprint import pprint

In [164]:
import nginx_auth_basic_blocker_meta as content
for m in (content, ):
    reload(m)
# </ignore> end meta code for Jupyter notebook blog

Expected outcome

I want to deploy a Dokku hosted Nginx server for serving static files that implements auth_basic so that when a request is made for a file the requester must enter a username and password.

NB: A high level of security is not required. I only want to keep out casual observers.

Actual outcome

When I deploy the app via

# 'docs' is app name
sudo dokku ps:rebuild docs

Dokku almost gets to the end of the deploy and then returns

...unknown directive "auth_basic"...

Update: blocker removed

With a suggestion from @savant aka José Diaz-Gonzalez at https://github.com/gliderlabs

Changed the Nginx ./config from:

--without-http_auth_basic_module \ to ``

Result: Nginx compiles

Apperently the default is that it compiles with the module.

Explicitly compiling with a --with-http_auth_basic_module is rejected.


In [165]:
content.display(content.wat())


Authentication challenge issued by nginx server after following the suggestion and recompiling:


In [166]:
url = 'http://docs.zip.thruhere.net/index.html'
response = !curl -s $url
_, _, _, response, *_ = response
content.display(content.HTML(response))


401 Authorization Required

Thanks to @savant aka José Diaz-Gonzalez for the help.


In [167]:
content.display(content.tweet())


' '

environment


In [168]:
content.print_outputs()


           docker version          Docker version 1.12.5, build 7392c3b
            dokku version           0.7.2
                buildpack          https://github.com/dm-wyncode/buildpack-nginx

Custom Nginx config template nginx.conf.erb

worker_processes 1;
error_log stderr;
pid nginx.pid;
daemon off;

events {
  worker_connections 768;
}

# custom nginx config
http {
  types_hash_max_size 2048;
  include mime.types;
  server {
    listen <%= ENV["PORT"] %>;
    server_name  _;
    <% if ENV["ROOT"] %>
      root /app/www/<%= ENV["ROOT"] %>;
    <% else %>
      root /app/www;
    <% end %>
    location / {
      auth_basic           "closed site";
      auth_basic_user_file /app/nginx/passwords;
      # I have tried this, too.Some posts said the path is relative to nginx.con
      # auth_basic_user_file passwords;
    }
    index index.html;
  }
}

Things I tried:

Upgraded to most current version of Nginx:


In [169]:
print(content.nginx_version)


# Nginx 1.11.8
NGINX_VERSION="1.11.8"
NGINX_TARBALL="nginx-${NGINX_VERSION}.tar.gz"
PCRE_VERSION="8.39"
PCRE_TARBALL="pcre-${PCRE_VERSION}.tar.gz"
ZLIB_VERSION="1.2.8"
ZLIB_TARBALL="zlib-${ZLIB_VERSION}.tar.gz"

result: Still get unexpected behavior.

Changed the location directive to this:

location / {
      # auth_basic           "closed site";
      # auth_basic_user_file /app/nginx/passwords;
      # I have tried this, too.Some posts said the path is relative to nginx.con
      # auth_basic_user_file passwords;
    }

Result: app functions as expected

Changed the Nginx ./config from:

--without-http_auth_basic_module \ to --with-http_auth_basic_module \

Result --with-http_auth_basic_module \ option not recognized and does not compile

link to ./configure in ./bin/compile