【问题标题】:Apache docker container - Invalid command 'RewriteEngine'Apache docker 容器 - 无效命令“RewriteEngine”
【发布时间】:2016-09-01 00:10:30
【问题描述】:

我使用 docker compose。但是,当我运行“docker-compose up”时,我遇到了一个错误:/var/www/html/.htaccess: Invalid command 'RewriteEngine'。

你能告诉我哪里失败了吗?

项目架构:

project-name /
             / docker-compose.yml
             / Dockerfile
             / apache.conf
             / php.ini
             / src /
                   / index.php
                   / .htaccess

docker-compose.yml:

web:
    build: .
    ports:
        - "80:80"
    volumes:
        - ./src:/var/www/html
        - php.ini:/usr/local/etc/php/conf.d/30-custom.ini
        - apache.conf:/etc/apache2/sites-enabled
    environment:
        - ALLOW_OVERRIDE=true

Docker 文件:

FROM php:7.0-apache

RUN a2enmod rewrite

RUN service apache2 restart

ADD ./src /var/www/html

php.ini:

display_errors=1
error_reporting=E_ALL

apache.conf(带有我的 IP 地址):

<VirtualHost *:80>
    ServerName xxx.xxx.xx.xxx
    DocumentRoot /var/www/html
</VirtualHost>

我在命令行中输入:

docker@default:/blabla/project-name$ docker-compose up

它返回我:

AH00558: apache2: Could not reliably determine the server's fully 
qualified domain name, using xxx.xx.x.x. Set the 'ServerName' directive 
globally to suppress this message

/var/www/html/.htaccess: Invalid command 'RewriteEngine', 
perhaps misspelled or defined by a module not included in the server
configuration

在浏览器中,在我的 IP 地址 (http://xxx.xxx.xx.xxx/) 中:

500 Internal servor error

我的 .htaccess :

<files .htaccess>
    Require all denied
</files>
Options +FollowSymlinks -Indexes -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$   /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]

我在 Windows 上,我使用 Oracle VM Virtual Box。

提前谢谢你!

编辑:我应该说,如果我删除重写规则,一切正常。

【问题讨论】:

  • 尝试删除RUN service apache2 restart这一行。构建映像时无需启动 Apache。
  • 总是同样的问题。

标签: php apache .htaccess docker docker-compose


【解决方案1】:

这对我有用:

# Dockerfile
FROM php:5.6-apache

MAINTAINER Raphael Mäder <me@randm.ch>

RUN a2enmod rewrite

ADD . /var/www/html

如果您之前已经构建了镜像,请不要忘记使用--build 运行您的docker-compose up 命令,否则它将运行可能未包含RUN a2enmod rewrite 语句的旧镜像。

【讨论】:

  • 有没有人知道如何从任何 httpd 图像中做到这一点?我对 apache+mod_rewrite 图像比 apache+php+mod_rewrite 图像更感兴趣。
【解决方案2】:

将此添加到您的 Dockerfile:

# Enable mod_rewrite for images with apache
RUN if command -v a2enmod >/dev/null 2>&1; then \
        a2enmod rewrite headers \
    ;fi

【讨论】:

    猜你喜欢
    • 2016-08-29
    • 2012-12-07
    • 2020-04-16
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多