Docker中的Apache说:不允许符号链接

时间:2015-10-27 15:16:05

标签: apache symfony docker docker-compose

我使用Docker镜像:https://github.com/docker-library/php/blob/fec7f537f049aafd2102202519c3ca9cb9576707/5.5/apache/Dockerfile

我将它用于docker-compose:

apache:
  build: ./site/docker/apachephp
  environment:
    - VIRTUAL_HOST=www.test.dev
  volumes:
    - ./site/code:/var/www/app
  expose:
    - "80"

代码是一个symfony应用程序,并在Web文件夹中使用符号链接,但对于符号链接中的所有资产,我都会在apache日志中找到:

AH00037:不允许使用符号链接或链接目标无法访问:/ var / www / app / web / test

所有其他代码运行正常 我想知道选项+ FollowSymLinks -SymLinksIfOwnerMatch 是否正确使用,是否有其他配置文件可以覆盖某些?

还是一些许可问题? 主机上的文件不属于apache用户www-data,但属于另一个用户,但是设置了读权限。

Apache配置是:

# see http://sources.debian.net/src/apache2/2.4.10-1/debian/config-dir/apache2.conf

Mutex file:/var/lock/apache2 default
PidFile /var/run/apache2/apache2.pid
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User www-data
Group www-data
HostnameLookups Off
ErrorLog /proc/self/fd/2
LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# ports.conf
Listen 80
<IfModule ssl_module>
    Listen 443
</IfModule>
<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

<Directory />
    AllowOverride None
    Require all denied
</Directory>

<Directory /var/www/app>
    Options +FollowSymLinks -SymLinksIfOwnerMatch
    AllowOverride All
    Require all granted
</Directory>

DocumentRoot /var/www/app/web

AccessFileName .htaccess
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

CustomLog /proc/self/fd/1 combined

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

# Multiple DirectoryIndex directives within the same context will add
# to the list of resources to look for rather than replace
# https://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex
DirectoryIndex disabled
DirectoryIndex app_dev.php index.php index.html

IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf

2 个答案:

答案 0 :(得分:1)

我也遇到了符号链接的问题,在我的情况下,这是因为链接具有从系统根目录开始的物理路径,而Docker以某种方式虚拟了实例的路径。如下:

analyticsSync-> / media / user / DATA / dev / web / ic / analytics / public / sync / analyticsSync

我通过创建相对的符号链接来解决它:

analyticsSync-> ic / analytics / public / sync / analyticsSync

“ / media / user / DATA”是我的数据分区的物理路径,Docker无法识别。

我希望这会有所帮助。

答案 1 :(得分:0)

回答我自己的问题: 感谢上面评论中的提示,我登录了容器并检查了pathes,而符号链接是主机的路径,因此无法工作。

所以我可能不得不在容器中创建符号链接,除非有某种方法告诉docker跟踪来自主机的符号链接,但我对此表示怀疑。