如何在 docker 上的 silverstripe 中配置 htaccess 文件?
How can I configure the htaccess file in silverstripe on docker?
我有一个基于 SilverStripe 框架的项目,我想将它移动到 docker,但是在 docker 配置之后,从 [=14= 加载项目时出现了一些问题] 文件夹。在我的本地 wamp 上没有 docker 的情况下它工作正常,但是在继续 docker 之后,它无法识别我的友好 URL。例如 http://localhost:8080/admin
Dockerfile
:
FROM php:7.3-apache
ENV DOCUMENT_ROOT /var/www/html/public
COPY . $DOCUMENT_ROOT
WORKDIR $DOCUMENT_ROOT
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY composer.json composer.json
COPY composer.lock composer.lock
#RUN composer install --no-dev
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf &&\
a2enmod rewrite &&\
service apache2 restart
RUN apt-get update && apt-get install -y apt-transport-https
RUN apt-get install -y libicu-dev
RUN docker-php-ext-configure intl && docker-php-ext-install intl
RUN docker-php-ext-install mysqli pdo pdo_mysql
docker-compose.yml
:
version: '3.8'
services:
web:
image: backend
working_dir: /var/www/html
volumes:
- .:/var/www/html
ports:
- 8080:80
database:
image: mysql:5.7
volumes:
- db-data:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
environment:
PMA_HOST: database
PMA_USER: root
PMA_PASSWORD:
UPLOAD_LIMIT: 1280M
MEMORY_LIMIT: 1280M
MAX_EXECUTION_TIME: 600
ports:
- 8089:80
volumes:
db-data:
.htaccess
文件:
RewriteEngine On
RewriteRule ^(.*)$ public/
经过调查,我发现以下 .htaccess
文件可以解决问题:
RewriteEngine On
Options Indexes SymLinksIfOwnerMatch FollowSymLinks
DirectoryIndex index.php index.html /example.php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{DOCUMENT_ROOT}/public/ -f
RewriteRule (.+) public/ [L]
RewriteRule (.*) public/index.php?path= [L,QSA]
我有一个基于 SilverStripe 框架的项目,我想将它移动到 docker,但是在 docker 配置之后,从 [=14= 加载项目时出现了一些问题] 文件夹。在我的本地 wamp 上没有 docker 的情况下它工作正常,但是在继续 docker 之后,它无法识别我的友好 URL。例如 http://localhost:8080/admin
Dockerfile
:
FROM php:7.3-apache
ENV DOCUMENT_ROOT /var/www/html/public
COPY . $DOCUMENT_ROOT
WORKDIR $DOCUMENT_ROOT
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY composer.json composer.json
COPY composer.lock composer.lock
#RUN composer install --no-dev
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf &&\
a2enmod rewrite &&\
service apache2 restart
RUN apt-get update && apt-get install -y apt-transport-https
RUN apt-get install -y libicu-dev
RUN docker-php-ext-configure intl && docker-php-ext-install intl
RUN docker-php-ext-install mysqli pdo pdo_mysql
docker-compose.yml
:
version: '3.8'
services:
web:
image: backend
working_dir: /var/www/html
volumes:
- .:/var/www/html
ports:
- 8080:80
database:
image: mysql:5.7
volumes:
- db-data:/var/lib/mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=true
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
environment:
PMA_HOST: database
PMA_USER: root
PMA_PASSWORD:
UPLOAD_LIMIT: 1280M
MEMORY_LIMIT: 1280M
MAX_EXECUTION_TIME: 600
ports:
- 8089:80
volumes:
db-data:
.htaccess
文件:
RewriteEngine On
RewriteRule ^(.*)$ public/
经过调查,我发现以下 .htaccess
文件可以解决问题:
RewriteEngine On
Options Indexes SymLinksIfOwnerMatch FollowSymLinks
DirectoryIndex index.php index.html /example.php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{DOCUMENT_ROOT}/public/ -f
RewriteRule (.+) public/ [L]
RewriteRule (.*) public/index.php?path= [L,QSA]