apache - 为什么我收到错误 "You don' t have permission to access/on this server."?

标签 apache ubuntu docker docker-compose yii2-advanced-app

我尝试在 docker 上运行我的网站,这是我的 docker-compose.yml:

version: '2'
services:
  php:
    image: yiisoftware/yii2-php:7.1-apache
  volumes:
    - ~/projects/my-project-name.local/composer- 
    docker/cache:/root/.composer/cache:delegated
    - ./:/app:delegated
  ports:
    - '8000:80'

当我运行“docker-compose up -d --build”并打开一个 url localhost:8000 时,发生错误“Forbidden.You don't have permission to access/on this server.”
容器的日志是:
AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.22.0.2. Set the 'ServerName' directive globally to suppress this message
AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.22.0.2. Set the 'ServerName' directive globally to suppress this message
[Tue Jul 10 06:42:22.442648 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) configured -- resuming normal operations
[Tue Jul 10 06:42:22.442713 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
[Tue Jul 10 06:42:25.985025 2018] [core:error] [pid 17] [client 172.22.0.1:48650] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html
172.22.0.1 - - [10/Jul/2018:06:42:25 +0000] "GET / HTTP/1.1" 403 503 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"
[Tue Jul 10 06:42:26.117774 2018] [core:error] [pid 17] [client 172.22.0.1:48650] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html, referer: http://localhost:8000/
172.22.0.1 - - [10/Jul/2018:06:42:26 +0000] "GET /favicon.ico HTTP/1.1" 403 513 "http://localhost:8000/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"

当我使用与 yii2 相同的 docker-compose.yml 时,一切正常。
请帮我解决这个问题。我的操作系统是 Ubuntu-18.04。

最佳答案

yii2 docker 镜像基于 php 镜像,在其 Dockerfile 中有以下几行:

# Copy the app code into the image
COPY . /var/www/html

这与日志中的警告一致。

当你把它添加到你的 Dockerfile 中时,你应该没问题(假设你的源代码在当前目录中)。

如果你想使用 docker 容器作为开发环境,你可以将源代码的文件夹挂载到 /var/www/html .在这种情况下,您必须添加一个卷:
volumes:
  - .:/var/www/html # Add this line

关于apache - 为什么我收到错误 "You don' t have permission to access/on this server."?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51258971/

相关文章:

java - Apache cxf jaxrs 服务器 ServiceConstructionException

php - 如何防止 <meta http-equiv ="refresh"> 攻击?

ruby-on-rails - 瘦服务器无法在 Amazon Ec2 上的生产模式(实时)下工作

PHP 7 RC3 : How to install missing MySQL PDO

Apache 2.4.7 403 禁止错误

ssh - 从 Docker 容器添加 Ruby SDK 作为 RubyMine 上的远程 SDK

docker - 是否可以在同一台机器上启动多个 docker 守护进程

linux - Git pull : Change Authentication

node.js - Docker错误: no such file or directory,打开 '/package.json'

php - 使用不同的参数处理 .htaccess 重定向?