Tha*_*Guy 5 php apache rest mod-rewrite docker
在我的本地计算机上,我让它工作(尽管我必须修改重写规则)。但是当尝试使用 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"
Run Code Online (Sandbox Code Playgroud)
在我看来,错误发生在a2enconf,因为如果我使用.htaccess文件并在 中添加以下行,它就可以工作volumes:
- "./code/rest.conf:/var/www/html/.htaccess:Z"
Run Code Online (Sandbox Code Playgroud)
FROM php:5.6-apache
RUN a2enmod rewrite
COPY rest.conf /etc/apache2/conf-available/
RUN a2enconf rest
Run Code Online (Sandbox Code Playgroud)
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ server.php
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
# 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
Run Code Online (Sandbox Code Playgroud)
你缺少RewriteOptions InheritDown:
RewriteOptions InheritDown
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ server.php
Run Code Online (Sandbox Code Playgroud)
因为rest.conf 被放置在VirtualHost 之外。
但我更喜欢这样做:
休息配置文件
<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>
Run Code Online (Sandbox Code Playgroud)
Dockerfile
FROM php:5.6-apache
RUN a2enmod rewrite
COPY rest.conf /etc/apache2/sites-enabled/000-default.conf
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11800 次 |
| 最近记录: |