首页 > 解决方案 > Docker 容器在使用 .htaccess 时出现内部服务器错误

问题描述

当我在没有 htaccess 的情况下在 docker contaner 中运行我的应用程序时,它可以完美运行。但是当我将 .htaccess 添加到重写规则时,它会在此处导致内部服务器。我还授予了 apache vhost 的权限,但结果仍然相同。

这是我的码头文件

FROM php:7.2-apache

RUN apt-get update

RUN apt-get install -y wget lsb-release gnupg2

RUN echo "deb http://packages.couchbase.com/ubuntu bionic bionic/main" | tee /etc/apt/sources.list.d/couchbase.list

RUN wget -O - http://packages.couchbase.com/ubuntu/couchbase.key | apt-key  add -

RUN apt-get update

#RUN apt search libcouchbase

RUN apt-get install -y  libcouchbase2-libevent libcouchbase-dev

RUN apt-get update

RUN pecl install https://packages.couchbase.com/clients/php/couchbase-2.6.2.tgz 

COPY ./config/php/php.ini /usr/local/etc/php/

#WORKDIR /var/www/html/

#COPY ./pos/backend/ /var/www/html/pos/backend/

RUN chown www-data:www-data . -R

RUN a2enmod rewrite

EXPOSE 80

这是我的 docker-compose

version: '3.1'

services:
  php:
    container_name: php_apache
    depends_on:
      - db
    build:
      context: .
    ports:
      - "80:80"
    restart: always  
    volumes:
      - ./config/vhosts:/etc/apache2/sites-enabled
      - ./backend/:/var/www/html/

  db:
    image: couchbase:community-6.6.0
    container_name: couchbase_server
    deploy:
      replicas: 1
    volumes:
      - ~/couchbase/node1:/opt/couchbase/var
    ports:
      - 8091:8091
      - 8092:8092
      - 8093:8093
      - 8094:8094
      - 11210:11210  

这是我的 htaccess 文件

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f   ls
  RewriteRule ^ index.php [QSA,L]  
</IfModule> 

vhost 文件 apache default.conf

<Directory /var/www/>
        Require all granted
</Directory>  

标签: phpdockerapache.htaccess

解决方案


不知道发生了什么,但我在谷歌上找到了这个,它解决了我的问题。万一如果有些脸相同

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

推荐阅读