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

14 篇文章 0 订阅

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

 

六、测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值