docker - Docker 容器基本身份验证中的 Nginx

标签 docker nginx

我正在通过 Docker 容器运行一个 nginx 网站,我正在尝试添加基本授权。这是我的 default.conf 文件。授权根本没有出现。任何人都可以给我任何指示吗?

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;

        auth_basic              "Restricted";
        auth_basic_user_file    /etc/nginx/.htpasswd;
    }

    #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;
    #}
}

这是我正在使用的 Dockerfile


ADD ./gilbard /usr/share/nginx/html

COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./htpasswd /etc/nginx/.htpasswd

# Expose port
EXPOSE 80

最佳答案

更新:我切换到另一个端口 (8080),它现在可以工作了。我认为这是因为我的浏览器正在缓存信息。我刷新了缓存,它现在也在 8000 端口上工作了

关于docker - Docker 容器基本身份验证中的 Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58192140/

相关文章:

postgresql - 在docker环境下为tcp md5配置Postgres

Docker 中的 Python 日志记录

Nginx - 我怎么知道 $http_referer 何时未设置或为空?

nginx - 将多个 nginx 配置组合成一个

nginx 读取自定义响应头

windows - 如何在 Windows 10 Pro 中完全卸载 Minikube? (巧克力)

mysql - 有时在Docker中导入数据Mysql很慢

docker - 查看与标签关联的dockerFile

nginx - 如何根据 header 的值进行 nginx 重定向?

caching - nginx proxy_cache key hash 在每个其他浏览器请求上发生变化