.htaccess重定向“;“未找到文件”;将Docker与PHP和Apache结合使用

.htaccess重定向“;“未找到文件”;将Docker与PHP和Apache结合使用,php,apache,.htaccess,docker,mod-rewrite,Php,Apache,.htaccess,Docker,Mod Rewrite,我正在尝试将一个运行在Apache和PHP上的现有web应用程序容器化。我让它在macOS的内置Apache服务器上本地运行,并提供PHP,但我正在尝试转移到Docker 我在repo root的docker-compose.yml中定义了单独的Apache和PHP容器,如下所示: version: '3' services: apache: build: .docker/apache container_name: redactedname_apache

我正在尝试将一个运行在Apache和PHP上的现有web应用程序容器化。我让它在macOS的内置Apache服务器上本地运行,并提供PHP,但我正在尝试转移到Docker

我在repo root的docker-compose.yml中定义了单独的Apache和PHP容器,如下所示:

version: '3'
services:
    apache:
        build: .docker/apache
        container_name: redactedname_apache
        ports:
            - 8080:80
        volumes:
            - .docker/config/vhosts:/etc/apache2/sites-enabled
            - .:/home/wwwroot
        depends_on:
            - php

    php:
        build: .docker/php
        container_name: redactedname_php
        volumes:
            - .:/home/wwwroot
现有的回购协议是由2个Symfony版本(1和3)和一系列其他内容组成的大杂烩。它的根目录中有一个
.htaccess
文件,用于将请求定向到相应版本的Symfony。每个Symfony目录也有自己的
。htaccess

├── redacted-repo-name/
│   ├── .htaccess
│   ├── symfony/           # Symfony 1 repo
│   │   └── .htaccess
│   └── redactedname/      # Symfony 3 repo
│       └── .htaccess
运行
docker compose-up--build
构建并运行docker容器,不会出现任何问题。但是,转到
localhost:8080
会给我一条消息“未找到文件”。我知道这是vhost或htaccess问题

我的vhost如下所示:

<VirtualHost *:80>

    Define server_name redactedname.local
    Define docrootweb /home/wwwroot
    Define logdir /var/log/apache2/

    DocumentRoot ${docrootweb}
    ServerName ${server_name}
    ServerAlias wwww.${server_name}
    ErrorLog ${logdir}/error.log
    CustomLog ${logdir}/access.log Combined

    DirectoryIndex index.php
    SetEnv APPLICATION_ENV dev

    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

    <Directory ${docrootweb}>
        AllowOverride All
        Allow from All
        Require all granted
        DirectoryIndex index.php index.html
    </Directory>

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>

    <FilesMatch .php$>
        SetHandler "proxy:fcgi://redactedname_php:9000"
    </FilesMatch>

    Undefine server_name
    Undefine docrootweb
    Undefine logdir
</VirtualHost>
RewriteRule^index.php(.*)/symfony/web/index.php/$1[QSA,L]
应该处理localhost:8080/,但我看到“找不到文件”

如果我将浏览器指向
localhost:8080/symfony/web/index.php
我会得到正确的页面

可能需要注意的是,Symfony 1和Symfony 3的根目录中的
.htaccess
文件如下所示:

<VirtualHost *:80>

    Define server_name redactedname.local
    Define docrootweb /home/wwwroot
    Define logdir /var/log/apache2/

    DocumentRoot ${docrootweb}
    ServerName ${server_name}
    ServerAlias wwww.${server_name}
    ErrorLog ${logdir}/error.log
    CustomLog ${logdir}/access.log Combined

    DirectoryIndex index.php
    SetEnv APPLICATION_ENV dev

    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

    <Directory ${docrootweb}>
        AllowOverride All
        Allow from All
        Require all granted
        DirectoryIndex index.php index.html
    </Directory>

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>

    <FilesMatch .php$>
        SetHandler "proxy:fcgi://redactedname_php:9000"
    </FilesMatch>

    Undefine server_name
    Undefine docrootweb
    Undefine logdir
</VirtualHost>
symfony/.htaccess(symfony 1):

redactedname/.htaccess(Symfony 3):


谢谢你的帮助!我正试图在我的组织中推动Docker/containers,使其工作是一个先决条件,因此非常感谢任何帮助

你读过这个答案吗?您可能需要让
在您的应用程序中运行a2enmod rewrite
Dockerfile@Tim我的apache Dockerfile中有这样一个文件:
运行a2enmod proxy\u fcgi ssl rewrite proxy\u balancer proxy\u http
,所以我认为这不是问题所在
RewriteEngine On
RewriteRule ^(.*)$ /symfony/web/$1 [L]
RewriteEngine On
RewriteRule ^(.*)$ /redactedname/web/$1 [L]