Add nginx auth
parent
cb8a5b0a37
commit
435adffb8a
|
@ -0,0 +1,30 @@
|
|||
# This compose file will boot a typical nginx-web toplogy
|
||||
# nginx: can set user/password to access, and forward request to web.
|
||||
# web: listen on private network
|
||||
# https://github.com/yeasy/docker-compose-files
|
||||
|
||||
#backend web application
|
||||
web:
|
||||
image: yeasy/simple-web:latest
|
||||
hostname: web
|
||||
expose:
|
||||
- "80"
|
||||
|
||||
#nginx to forward request
|
||||
nginx:
|
||||
image: yeasy/nginx:test
|
||||
hostname: nginx
|
||||
links:
|
||||
- web:web
|
||||
volumes:
|
||||
- ./docker-entrypoint.sh:/tmp/docker-entrypoint.sh
|
||||
- ./nginx.default.conf:/etc/nginx/nginx.default.conf
|
||||
ports:
|
||||
- "80:80"
|
||||
environment:
|
||||
- BACKEND=web
|
||||
- PORT=80
|
||||
- USERNAME=user
|
||||
- PASSWORD=pass
|
||||
command: bash /tmp/docker-entrypoint.sh
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
backend="${BACKEND:-web}"
|
||||
port="${PORT:-80}"
|
||||
username="${USERNAME:-user}"
|
||||
password="${PASSWORD:-pass}"
|
||||
|
||||
htpasswd -c -b /etc/nginx/.htpasswd "$username" "$password"
|
||||
|
||||
sed "s/BACKEND/$backend/; s/PORT/$port/" /etc/nginx/nginx.default.conf > /etc/nginx/nginx.conf
|
||||
|
||||
nginx -c /etc/nginx/nginx.conf
|
|
@ -0,0 +1,52 @@
|
|||
# This file should be put under /etc/nginx/conf.d/
|
||||
|
||||
user nginx;
|
||||
worker_processes 1;
|
||||
daemon off;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
location / {
|
||||
auth_basic "Login";
|
||||
auth_basic_user_file /etc/nginx/.htpasswd;
|
||||
proxy_pass http://BACKEND:PORT;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root html;
|
||||
}
|
||||
}
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
Loading…
Reference in New Issue