原文鏈接:https://blog.csdn.net/w_meng_h/article/details/93393589
一、使用docker安裝nginx
https://blog.csdn.net/W_Meng_H/article/details/93391470
二、在nginx容器內部,配置用戶和密碼
#查看運行容器的ID docker ps #進入nginx容器 docker exec -it 容器ID /bin/bash #容器內部操作 #更新軟件源 apt-get update #安裝apache2-utils apt-get install apache2-utils #創建用戶名 htpasswd -c /etc/nginx/passwd.db 用戶名 #輸入密碼(自動彈出) New password: Re-type new password: #查看用戶和密碼 cat /etc/nginx/passwd.db #退出 exit
三、修改配置文件
server { listen 80; server_name 域名; access_log /var/log/nginx/logging.access.log main; location / { auth_basic "Please input password"; #這里是驗證時的提示信息 auth_basic_user_file /etc/nginx/passwd.db; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://IP:8088; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }
四、修改容器時間
#查看宿主機的時間 輸入如下命令查看 data -R #修改容器時間和宿主機相同 docker cp /etc/localtime 容器ID:/etc/
五、重啟容器
docker restart 容器ID
六、測試