本文介绍了Apache docker 容器 - 无效的命令“RewriteEngine"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use docker compose. However, when I run "docker-compose up", I came across an error : /var/www/html/.htaccess: Invalid command 'RewriteEngine'.

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

Can you tell me where I fails ??

项目架构:

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

docker-compose.yml :

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

Dockerfile:

Dockerfile :

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 地址):

apache.conf (with my ip address) :

<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/) :

and in the browser, in my ip address (http://xxx.xxx.xx.xxx/) :

500 Internal servor error

我的 .htaccess :

my .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.

I'm on windows and i use Oracle VM Virtual Box.

先谢谢你!

我应该说,如果我删除重写规则,一切正常.

EDIT : I should say that if I delete rewrite rules, everything works.

推荐答案

这对我有用:

# Dockerfile
FROM php:5.6-apache

MAINTAINER Raphael Mäder <[email protected]>

RUN a2enmod rewrite

ADD . /var/www/html

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

Don't forget to run your docker-compose up command with --build if you have already built the image previously, otherwise it will run the old image which may have not included the RUN a2enmod rewrite statement.

这篇关于Apache docker 容器 - 无效的命令“RewriteEngine"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:51