简体   繁体   English

Symfony 3,域名显示目录结构

[英]Symfony 3, domain name shows Directory Structure

I know this question is asked a lot but I read all the questions related to this but they didn't solve my problem. 我知道这个问题经常被问到,但是我阅读了与此相关的所有问题,但是它们并不能解决我的问题。

I just deployed a Symfony 3 web app and I followed the Symfony server configuration documentation just to find out that the www.domain.com displays the directory structure! 我刚刚部署了Symfony 3 Web应用程序,并且遵循Symfony服务器配置文档,只是发现www.domain.com显示目录结构!

Here's the configuration that I used of file /etc/apache2/sites-available/site.com.conf : 这是我使用的/etc/apache2/sites-available/site.com.conf文件的配置:

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

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

    <IfModule mod_rewrite.c>
        Options -MultiViews
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ app.php [QSA,L]
    </IfModule>
</Directory>


ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

I can see the app when I go to www.domain.com/web and www.domain.com/web/app.php 当我转到www.domain.com/web和www.domain.com/web/app.php时,我可以看到该应用程序

I want to be able to visit www.domain.com and see the app. 我希望能够访问www.domain.com并查看该应用程序。

Change the line: 更改行:

AllowOverride None

to next one: 下一个:

AllowOverride All

Remove section <IfModule mod_rewrite.c> And use standard Symfony's .htaccess file. 删除<IfModule mod_rewrite.c>并使用标准Symfony的.htaccess文件。

Also you need to set up PHP as module for your apache. 另外,您需要将PHP设置为您的Apache模块。 Be sure to have uncommented line in http.conf that loads PHP module: 确保在加载PHP模块的http.conf中有未注释的行:

LoadModule php7_module libexec/apache2/libphp7.so

You are missing your DirectoryIndex app.php or DirectoryIndex dev_app.php contained in your directory tag. 您缺少目录标记中包含的DirectoryIndex app.phpDirectoryIndex dev_app.php This will cause apache to load app.php if a file has not been requested. 如果未请求文件,这将导致apache加载app.php。 https://httpd.apache.org/docs/2.0/mod/mod_dir.html https://httpd.apache.org/docs/2.0/mod/mod_dir.html

<Directory /var/www/project/web>
    DirectoryIndex app.php
    ...
</Directory>

Also make sure mod rewrite is enabled. 还要确保启用了mod rewrite。 a2enmod rewrite You may have to use sudo. a2enmod rewrite您可能必须使用sudo。

One final note: Options -MultiViews should be contained inside the <Directory> for use all the time and not just when mod_rewrite is enabled. 最后一点: Options -MultiViews应该包含在<Directory> ,以便始终使用,而不仅仅是在启用mod_rewrite时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM