首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Docker容器中的Apache a2enconf

Docker容器中的Apache a2enconf
EN

Stack Overflow用户
提问于 2017-07-17 21:11:42
回答 1查看 9.6K关注 0票数 5

我试图追随在这段代码中获得的本教程,但没有成功。

在我的本地机器上,我让它工作(,尽管我必须修改重写规则)。但是,当尝试使用Docker容器时,当我尝试访问示例REST资源时,会得到错误404:

代码语言:javascript
复制
$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中添加了下面一行,它就能工作了。

代码语言:javascript
复制
- "./code/rest.conf:/var/www/html/.htaccess:Z"

Dockerfile

代码语言:javascript
复制
FROM php:5.6-apache
RUN a2enmod rewrite
COPY rest.conf /etc/apache2/conf-available/
RUN a2enconf rest

rest.conf

代码语言:javascript
复制
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ server.php

docker-compose.yml

代码语言:javascript
复制
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

在容器内

代码语言:javascript
复制
# 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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-19 19:08:20

你缺少RewriteOptions InheritDown

代码语言:javascript
复制
  RewriteOptions InheritDown
  RewriteEngine on
  RewriteCond %{REQUEST_URI} !^/$
  RewriteRule ^(.*)$ server.php

因为rest.conf被放置在VirtualHost之外。

但我宁愿这样做:

rest.conf

代码语言:javascript
复制
<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

代码语言:javascript
复制
FROM php:5.6-apache
RUN a2enmod rewrite
COPY rest.conf /etc/apache2/sites-enabled/000-default.conf
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45153746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档