将mod_rewrite添加到Docker镜像httpd:alpine [英] Add mod_rewrite to Docker image httpd:alpine

查看:329
本文介绍了将mod_rewrite添加到Docker镜像httpd:alpine的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说实话,我几乎没有使用Alpine Linux的经验,但是我喜欢它的方法,因此想改变它.我也是Docker的新手,所以如果这是一个愚蠢"的问题,请多多包涵.

我想实现的是基于httpd:alpine图像,并将HTTPd扩展到我的需求.

这将包括激活mod_rewrite模块并将自定义.htaccess复制到映像中.

这是我到目前为止所拥有的:

FROM httpd:alpine

# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/

RUN apk update
RUN apk upgrade
RUN apk add apache2-utils
RUN a2enmod rewrite
RUN rc-service apache2 restart

现在的问题是,我不断收到找不到a2enmod"错误,我不知道该如何解决.那可能是因为a2enmod是纯粹的Debian/Ubuntu/...东西,但是我不知道有任何其他激活mod_rewrite的方法(或与此相关的任何模块).

非常感谢大家的支持!

解决方案

mod_rewrite默认情况下是在高山地区使用apache安装的,因此无需再次安装.因此,这是在Alpine中启用mod_rewrite的方式:

FROM httpd:alpine

# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/

RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf

RUN { \
  echo 'IncludeOptional conf.d/*.conf'; \
} >> /usr/local/apache2/conf/httpd.conf \
  && mkdir /usr/local/apache2/conf.d

I have almost no experience with Alpine Linux, to be honest, but I like its approach and therefore want to change that. I'm also relatively new to Docker, so please bear with me if this is a "stupid" question.

What I would like to achieve is building upon the httpd:alpine image and extending the HTTPd to my needs.

That would include activating the mod_rewrite module and copying a custom .htaccess into the image.

Here is what I have so far:

FROM httpd:alpine

# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/

RUN apk update
RUN apk upgrade
RUN apk add apache2-utils
RUN a2enmod rewrite
RUN rc-service apache2 restart

My issue is now, that I constantly receive an "a2enmod not found" error, which I don't know how to resolve. That might be because a2enmod is a pure Debian/Ubuntu/... thing, but I don't know any alternative way of activating mod_rewrite (or any module for that matter).

Thank you all very much in advance for your support!

解决方案

mod_rewrite is installed by default with apache in alpine, so no need to install it again. So here's how you enable mod_rewrite in Alpine:

FROM httpd:alpine

# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/

RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf

RUN { \
  echo 'IncludeOptional conf.d/*.conf'; \
} >> /usr/local/apache2/conf/httpd.conf \
  && mkdir /usr/local/apache2/conf.d

这篇关于将mod_rewrite添加到Docker镜像httpd:alpine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆