Sta*_*ker 4 apache docker kubernetes
我正在对 Laravel 应用程序进行 docker 化,我的图像基于 apache 图像,该图像托管在 AKS 中,我在 /public/images 内挂载图像共享的 azure 文件,问题是 apache 会在图像内添加标头导致图像损坏
即使我在 pod 本身内部执行并尝试curl localhost,我也会遇到同样的问题,所以我确信这不是路由或我的入口的问题
FROM php:7.3-apache
#install all the system dependencies and enable PHP modules
RUN apt-get update -y && apt-get install -y libmcrypt-dev openssl
RUN apt-get update && apt-get install -y libmcrypt-dev \
&& pecl install mcrypt-1.0.2 \
&& docker-php-ext-enable mcrypt
RUN docker-php-ext-install pdo mbstring
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
RUN apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev && \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install mysqli pdo pdo_mysql
# RUN apt-get install wget
RUN apt-get update; apt-get install curl -y
#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
#set our application folder as an environment variable
ENV APP_HOME /var/www/html
#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
#change the web_root to laravel /var/www/html/public folder
#RUN sed -i -e "s/html/html\/public/g" /etc/apache2/sites-enabled/000-default.conf
COPY vhost.conf /etc/apache2/sites-available/000-default.conf
RUN echo "EnableSendfile off" >> /etc/apache2/apache2.conf
# enable apache module rewrite
RUN a2enmod rewrite
#copy source files and run composer
COPY . $APP_HOME
# install all PHP dependencies
RUN composer install --no-interaction
#change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME
Run Code Online (Sandbox Code Playgroud)
接下来使用常规部署 yaml 文件将其推送到 kubernetes,并安装以下卷:
volumeMounts:
- name: sessions
mountPath: /var/www/html/storage/framework/sessions
- name: cache
mountPath: /var/www/html/storage/framework/cache
- name: views
mountPath: /var/www/html/storage/framework/views
- name: images
mountPath: /var/www/html/public/images
Run Code Online (Sandbox Code Playgroud)
卷:
现在的问题是,如果我尝试从图像文件夹访问静态文件,例如使用“https://www.somedomain.com/images/somefile.png”之类的网址
该文件将被下载,但 apache 会将上述标头附加到内容中,从而导致损坏。
除了卷安装中的任何文件外,Web 应用程序运行得非常好。
如果我执行“kubectl exec -it podname -- bash”并浏览文件,我可以看到卷安装工作正常,而且如果我尝试从应用程序界面上传文件,文件将以写入方式写入文件夹内,唯一的问题是浏览文件。
我们解决了这个问题,只是在 vhost.conf 中,我们需要关闭 EnableMMAP
EnableMMAP off
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
654 次 |
最近记录: |