.htaccess 与 .htpasswd 密码不匹配

问题描述 投票:0回答:1

我正在尝试将在 Windows 上构建的网站放入 Docker 容器中。 该网站运行没有缺陷,但问题是当我尝试登录时,我在 Docker 容器的日志中收到此错误:

172.17.0.2:80 192.168.2.27 - - [03/Dec/2023:13:00:37 +0000] "GET / HTTP/1.1" 200 1597 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0"
172.17.0.2:80 192.168.2.27 - - [03/Dec/2023:13:00:43 +0000] "GET /admin/adminpanel.php HTTP/1.1" 401 728 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0"
[Sun Dec 03 13:00:46.198385 2023] [auth_basic:error] [pid 18] [client 192.168.2.27:61450] AH01617: user finn: authentication failure for "/admin/adminpanel.php": Password Mismatch
172.17.0.2:80 192.168.2.27 - finn [03/Dec/2023:13:00:46 +0000] "GET /admin/adminpanel.php HTTP/1.1" 401 727 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0"

这是 DockerFile:

# Use an official PHP runtime as a parent image
FROM php:7.4-apache

# Set the working directory to /var/www/html
WORKDIR /var/www/html

# Copy the current directory contents into the container at /var/www/html
COPY . /var/www/html

# Install additional dependencies and enable required Apache modules
RUN apt-get update \
    && apt-get install -y libpng-dev libjpeg-dev libzip-dev \
    && docker-php-ext-configure gd --with-jpeg \
    && docker-php-ext-install gd mysqli zip \
    && a2enmod rewrite \
    && service apache2 restart

# Set proper permissions for the Files directory
RUN chown -R www-data:www-data /var/www/html/Files \
    && chmod -R 755 /var/www/html/Files

# Copy the .htpasswd file to the correct location and set permissions
COPY --chmod=644 .htpasswd /var/www/html/admin/.htpasswd
RUN chmod 644 /var/www/html/admin/.htpasswd

# Update Apache configuration to allow .htaccess
RUN { \
    echo '<Directory /var/www/html/>'; \
    echo '    Options Indexes FollowSymLinks'; \
    echo '    AllowOverride All'; \
    echo '    Require all granted'; \
    echo '</Directory>'; \
} > /etc/apache2/sites-available/000-default.conf

# Expose port 80 for Apache
EXPOSE 80

# Start Apache in the foreground
CMD ["apache2-foreground"]

这是管理文件夹的 .htacces 文件:


AuthType Basic
AuthName "restricted area"
AuthUserFile /var/www/html/admin/.htpasswd
require valid-user

这是管理文件夹中的 .htpasswd 文件:

finn:test

我遇到了错误,它无法打开文件,但在使用 chmod 命令授予其权限后,该错误消失了,但密码现在不匹配。

php .htaccess dockerfile .htpasswd
1个回答
0
投票

.htpasswd
文件不应包含纯文本值,它们仅适用于 Windows:https://httpd.apache.org/docs/2.4/misc/password_cryptions.html。正如您所提到的,您正在使用 php7.4-apache docker 映像,该映像构建在 debian11-slim 之上

更改您的 Dockerfile 以包含运行

$ htpasswd -nbd finn test

或复制一个

.htpasswd
文件,其值在构建映像时已加密。

© www.soinside.com 2019 - 2024. All rights reserved.