我试图追随在这段代码中获得的本教程,但没有成功。
在我的本地机器上,我让它工作(,尽管我必须修改重写规则)。但是,当尝试使用Docker容器时,当我尝试访问示例REST资源时,会得到错误404:
$docker-compose logs -f
web_1 | 172.27.0.1 - - [19/Jul/2017:17:45:58 +0000] "GET /clients/jim HTTP/1.1" 404 501 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"
web_1 | 172.27.0.1 - - [19/Jul/2017:17:46:20 +0000] "GET /clients/anne HTTP/1.1" 404 502 "-" "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0"在我看来,这个错误发生在a2enconf上,因为如果我使用一个.htaccess文件并在volumes中添加了下面一行,它就能工作了。
- "./code/rest.conf:/var/www/html/.htaccess:Z"Dockerfile
FROM php:5.6-apache
RUN a2enmod rewrite
COPY rest.conf /etc/apache2/conf-available/
RUN a2enconf restrest.conf
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ server.phpdocker-compose.yml
version: '2'
services:
web:
image: myphp:5.6-apache-rewrite
ports:
- "80:80"
volumes:
- "./code/server.php:/var/www/html/server.php:Z"
restart: unless-stopped在容器内
# apache2ctl -t
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.27.0.2. Set the 'ServerName' directive globally to suppress this message
Syntax OK
# apache2ctl -M
Loaded Modules:
(...)
rewrite_module (shared)
(...)
# apache2ctl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.27.0.2. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:80 172.27.0.2 (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33发布于 2017-07-19 19:08:20
你缺少RewriteOptions InheritDown
RewriteOptions InheritDown
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ server.php因为rest.conf被放置在VirtualHost之外。
但我宁愿这样做:
rest.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ server.php
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Dockerfile
FROM php:5.6-apache
RUN a2enmod rewrite
COPY rest.conf /etc/apache2/sites-enabled/000-default.confhttps://stackoverflow.com/questions/45153746
复制相似问题