Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx in docker container basic auth

Tags:

docker

nginx

I am running an nginx website via a Docker container and I'm trying to add basic authorization. This is my default.conf file. The authorization doesn't come up at all. Can anyone give me any pointers?

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

Here is the Dockerfile that I am using


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

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

# Expose port
EXPOSE 80
like image 425
A.boyle Avatar asked Nov 21 '25 05:11

A.boyle


1 Answers

Update: I switched to a different port (8080) and it is working now. I think it's because my browser was caching information. I flushed the cache and it's now also working on port 8000

like image 175
A.boyle Avatar answered Nov 24 '25 04:11

A.boyle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!