Sign inSign up

ecsousa/nginx-basic-auth

By ecsousa

•Updated over 8 years ago

Basic auth nginx wrapper

Image
0

928

ecsousa/nginx-basic-auth repository overview

Note: Based upon https://github.com/davidhiendl/docker-nginx-basic-auth⁠

⁠NGINX Basic Auth Proxy Container

NGINX container pre-configured to act as a basic auth proxy. Simple way to protect HTTP services that don't have any authentication when OAuth or anything similar is to much.

⁠Configuration

Supports the following environment variables for configuration (with defaults):

VariableDefaultDescription
LISTEN_PORT80The port to bind to
AUTH_REALM"Restricted"The identification that will be provided via basic auth
HTPASSWD_FILE"/etc/nginx/conf.d/auth.htpasswd"Can be mounted into the container via Swarm Secret, Kubernetes Secret oder plain mount --bind
FORWARD_PROTOCOL"http"
FORWARD_PORT8080
FORWARD_HOST"example.localhost"

⁠Sample Configuration

Given the following configuration:

LISTEN_PORT=8080
AUTH_REALM=Restricted
HTPASSWD_FILE=/etc/nginx/conf.d/auth.htpasswd
FORWARD_PROTOCOL=http
FORWARD_PORT=80
FORWARD_HOST=localhost

Then NGINX will be configured like this: Contents of /etc/nginx/conf.d/auth.conf:

server {
    listen 8080 default_server;

    location / {
        # basic auth
        auth_basic           "Restricted";
        auth_basic_user_file /etc/nginx/conf.d/auth.htpasswd;

        # proxy pass
        proxy_pass         http://localhost:80;
        proxy_read_timeout 900;

        # forward headers
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Tag summary

Content type

Image

Digest

Size

9.4 MB

Last updated

over 8 years ago

docker pull ecsousa/nginx-basic-auth