Skip to content

Instantly share code, notes, and snippets.

@omerkoseoglu
Created October 19, 2020 07:58
Show Gist options
  • Save omerkoseoglu/1ef6c61fb51a0cfe2e26ca150f62284c to your computer and use it in GitHub Desktop.
Save omerkoseoglu/1ef6c61fb51a0cfe2e26ca150f62284c to your computer and use it in GitHub Desktop.
nginx basic auth
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
auth_basic "Restricted"; #For basic auth
auth_basic_user_file /etc/nginx/.htpasswd; #For basic auth
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
FROM nginx:alpine
RUN apk add --no-cache apache2-utils
RUN htpasswd -c -b /etc/nginx/.htpasswd exampleuser 123456
COPY default.conf /etc/nginx/conf.d/default.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment