大网数据广告活动
服务器运维问答

Docker httpd & htaccess - Could not open password file

· 52CE 我爱测

I have an error that I can't resolve, even with my last researches. Folder structure: -rw-r--r-- 1 root root 105 Aug 8 15:58 Dockerfile -rw-r--r-- 1 root root 21371 Aug 8 16:05 my-httpd.conf drwxr-xr-x 2 root root 4096 Aug 8 15:3…

问题原文

原帖链接 · Quentin Rey · CC BY-SA 4.0

I have an error that I can't resolve, even with my last researches.

Folder structure:

-rw-r--r-- 1 root root   105 Aug  8 15:58 Dockerfile
-rw-r--r-- 1 root root 21371 Aug  8 16:05 my-httpd.conf
drwxr-xr-x 2 root root  4096 Aug  8 15:37 www

1 - I create an image of apache with a simple Dockerfile

Dockerfile:

FROM httpd:2.4
WORKDIR /usr/local/apache2/htdocs
COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf

Command:

docker build -t apache .

2 - I run a container with the new image

Command:

docker run -v /MY_PATH/www/:/usr/local/apache2/htdocs/ -dit --name apache -p 80:80 apache

3 - I want to protect access of the www folder, with htaccess

Folder structure:

-rwxr-xr-x 1 root root  116 Aug  8 15:37 .htaccess
-rw-r--r-- 1 root root   46 Aug  8 15:34 .htpasswd
-rwxrwxrwx 1 root root  169 Aug  7 10:52 index.html
-rw-r--r-- 1 root root  354 Aug  7 10:56 master.css
-rw-r--r-- 1 root root   26 Aug  7 10:57 robots.txt

.htaccess

AuthType Basic
AuthName "Restricted Area"
AuthUserFile /MY_PATH/www/.htpasswd
Require valid-user

4 - I try to access the index.html on my browser

The connexion windows appears, I type my login, and password.

Then I have a 500 Internal Server Error

5 - Logs said that "Could not open password file"

When I check the apache container logs, I have this:

[Fri Aug 09 07:19:58.458778 2019] [authn_file:error] [pid 7:tid 140331369154304] (2)No such file or directory: [client 194.214.141.5:64325] AH01620: Could not open password file: /MY_PATH/www/.htpasswd
194.214.141.5 - user [09/Aug/2019:07:19:58 +0000] "GET / HTTP/1.1" 500 528
[Fri Aug 09 07:19:58.534805 2019] [authn_file:error] [pid 7:tid 140331135788800] (2)No such file or directory: [client 194.214.141.5:55037] AH01620: Could not open password file: /MY_PATH/www/.htpasswd, referer: http://mywebsite.com/

6 - I need your help :)

I search many times on Google, the only thing I found is about "SELinux", like this: Permission denied: Could not open password file.

I'm not sure that is the same here with the use of Docker.

So if someone can help me, it would be great! :)

已采纳解答

原帖链接 · Gerald Schneider · CC BY-SA 4.0

The Apache in the container does not know about your external path /MY_PATH/www/, you need to use the path inside the container:

AuthUserFile /usr/local/apache2/htdocs/.htpasswd

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-08-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。