【问题标题】:Why do I get the error "You don't have permission to access / on this server."?为什么我会收到错误消息“您无权访问此服务器上的 /。”?
【发布时间】:2018-12-17 22:19:20
【问题描述】:

我尝试在 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 时,出现错误“禁止访问。您无权访问此服务器上的 /。” 容器的日志是:

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。

【问题讨论】:

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


    【解决方案1】:

    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
    

    【讨论】:

    • 感谢您的回答。我只有docker-compose.yml,是否需要使用dockerfile?
    • 视情况而定。您想编辑源文件并将 docker 用作开发服务器吗?在这种情况下,您可以将当前文件夹作为卷挂载到 /var/www/html
    • 谢谢,我明白了
    猜你喜欢
    • 2017-11-22
    • 1970-01-01
    • 2018-02-09
    • 2012-06-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    相关资源
    最近更新 更多