使用docker部署nginx服务
docker-compose.yml
version: '3'
services:
web:
image: nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
restart: always
ports:
- "80:80"
- "443:443"
environment:
- NGINX_HOST=fengleer.cn
- NGINX_PORT=80
conf文件
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
server_name jupyter.my.local;
client_max_body_size 1G;
location / {
proxy_pass http://172.17.0.1:8086;
proxy_connect_timeout 3s;
proxy_read_timeout 5s;
proxy_send_timeout 3s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
}
}
}
配置密码
安装依赖
sudo apt-get install apache2-utils
生成用户名,密码对
#创建新的密码文件
htpasswd -c ./ht.passwd test
#向密码文件中追加用户
htpasswd -c ./ht.passwd test1
将密码文件挂载到docker中
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./ht.passwd:/etc/nginx/ht.passwd
针对对应的服务添加用户访问控制
server {
# ----
location / {
# ---
auth_basic "Please enter your username and password";
auth_basic_user_file /etc/nginx/htpasswd;
autoindex on;
}
}
标签:http,log,etc,访问控制,nginx,proxy,conf,docker
From: https://blog.csdn.net/fengle_er/article/details/139380363