docker-配置nginx访问页面密码,增加用户和密码,修改nginx容器时间

一、使用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  域名;

    #charset koi8-r;
    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  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;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 

四、修改容器时间

#查看宿主机的时间 输入如下命令查看
data -R

#修改容器时间和宿主机相同
docker cp /etc/localtime 容器ID:/etc/

 

五、重启容器

docker restart 容器ID

 

六、测试

docker-配置nginx访问页面密码,增加用户和密码,修改nginx容器时间_第1张图片

你可能感兴趣的:(Docker,Nginx)