指向 /project/current/web 的符号链接有效但不适用于 /project/current/web/app.php (Apache / Ubuntu / Symfony2)

Symlink to /project/current/web work but not to /project/current/web/app.php (Apache / Ubuntu / Symfony2)

Symlink 到 /var/www/myproject/current/web/ 正在工作,但正在列出 Web 目录(不好)。

Symlink 到 /var/www/myproject/current/web/app.php 不工作并给我这个错误:请求的 URL / 在此服务器上找不到。

/var/log/apache2/error.log 中没有日志,/var/log/apache2/access.log 中的这一行 - 404 错误

ip - - [17/Mar/2016:06:21:15 -0400] "GET / HTTP/1.1" 404 493 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"

设置如下:

Symfony2 + Capisfony + Apache + Ubuntu 14.04

这是我的 apache2.conf

<Directory />
        Options FollowSymLinks
        AllowOverride all
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

这是 /var/www/myproject/current/web

中的 .htaccess
    DirectoryIndex app.php

    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

RewriteCond %{REQUEST_URI}:: ^(/.+)/(.*)::$
RewriteRule ^(.*) - [E=BASE:%1]

RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>

        RedirectMatch 302 ^/$ /app.php/

    </IfModule>
</IfModule>

下面是我如何制作 sym link

rm -rf /var/www/html
ln -s /var/www/myproject/current/web/app.php /var/www/html
service apache2 restart

==> 404

rm -rf /var/www/html
ln -s /var/www/myproject/web/app.php /var/www/html
service apache2 restart

=> 您无权访问此服务器上的 /。

[Thu Mar 17 06:44:53.385300 2016] [core:error] [pid 19767] [client 88.14.213.213:51484] AH00037: Symbolic link not allowed or link target not accessible: /var/www/html

我建议你改用 apache 的虚拟主机:

它来自 symfony 食谱:http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

<VirtualHost *:80>
    ServerName domain.tld
    ServerAlias www.domain.tld

    DocumentRoot /var/www/project/web
    <Directory /var/www/project/web>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

你让apache管理文档根目录,你把app_dev.php添加到url使用dev环境,如果你有另一个env,比如staging,就方便测试prod env有时

要防止列出文件,请添加:

Options -Indexes 

到虚拟主机的目录部分

答案是:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride all
        Require all granted
</Directory>

AllowOverride None 阻止了 .htaccess

感谢您的帮助。