重写模式不适用于virtualhost和symfony4

时间:2019-09-08 16:37:31

标签: apache symfony mod-rewrite symfony4

我正在使用symfony4.3,该应用程序托管在vps ubuntu 18.04下。

我已经按照https://symfony.com/doc/current/setup/web_server_configuration.html来配置Web服务器,但是问题是该应用程序无法在重写模式下使用,但是在添加 / public / index 时可以使用。

>

我的意思是 www.mysite.com 不起作用。它显示文件夹和文件,但 www.mysite.com/public/index.php 显示网站内容。

域名受 https

保护。

这是配置:

<VirtualHost *:80>

    ServerAdmin webmaster@s****.com
    ServerName www.s****.com
    ServerAlias s****.com

    # For Apache 2.4.9 or higher
    # Using SetHandler avoids issues with using ProxyPassMatch in combination
    # with mod_rewrite or mod_autoindex
    <FilesMatch \.php$>
        SetHandler proxy:fcgi://127.0.0.1:9000
        # for Unix sockets, Apache 2.4.10 or higher
        # SetHandler proxy:unix:/path/to/fpm.sock|fcgi://dummy
    </FilesMatch>


    DocumentRoot /var/www/site/public
    DirectoryIndex /index.php

    <Directory /var/www/site/public>
        AllowOverride All
        Require all granted

        FallbackResource /index.php

        <IfModule mod_rewrite.c>
            RewriteEngine On

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

            # Sets the HTTP_AUTHORIZATION header removed by Apache
            RewriteCond %{HTTP:Authorization} .
            RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

            # Redirect to URI without front controller to prevent duplicate content
            # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
            #   following RewriteCond (best solution)
            RewriteCond %{ENV:REDIRECT_STATUS} ^$
            RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]

            # If the requested filename exists, simply serve it.
            # We only want to let Apache serve files and not directories.
            RewriteCond %{REQUEST_FILENAME} -f
            RewriteRule ^ - [L]

            # Rewrite all other queries to the front controller.
            RewriteRule ^ %{ENV:BASE}/index.php [L]
        </IfModule>

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

        <IfModule !mod_rewrite.c>
            <IfModule mod_alias.c>
                # When mod_rewrite is not available, we instruct a temporary redirect of
                # the start page to the front controller explicitly so that the website
                # and the generated links can still be used.
                RedirectMatch 307 ^/$ /index.php/
                # RedirectTemp cannot be used instead
            </IfModule>
        </IfModule>

    </Directory>

    # optionally disable the fallback resource for the asset directories
    # which will allow Apache to return a 404 error when files are
    # not found instead of passing the request to Symfony
    <Directory /var/www/site/public/bundles>
        FallbackResource disabled
    </Directory>

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

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

    # optionally set the value of the environment variables used in the application
    #SetEnv APP_ENV prod
    #SetEnv APP_SECRET <>
    #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"

</VirtualHost>

1 个答案:

答案 0 :(得分:0)

已解决:

我还有另一个文件default-ssl.conf,我必须将这些配置放在里面:

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerAdmin contact@s****.com

    ServerName www.s****.com
    ServerAlias s****.com

    DocumentRoot /var/www/site/public

    <Directory /var/www/site/public>

          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Allow from All
          Require all granted

          <IfModule mod_rewrite.c>

           # copy configuration here

    </VirtualHost>
</IfModule>