我有一个Laravel应用程序,是前一段时间创建的,它的图像目前正在运行,并在Google Cloud Run容器上工作。我需要对它进行一些更改,所以我试图使用Docker Desktop在我的Windows 11工作站上加载容器,但由于某种原因,当试图打开网页时,它正在下载二进制文件而不是提供页面。我怀疑它甚至没有到达Nginx,因为日志中没有显示访问正在发生。我很困惑为什么它在我的桌面上的行为与服务器完全不同,我认为这就是为什么我们开始使用容器(以避免这些问题)。这是相关文件。Dockerfile
FROM php:8.1.15-fpm-alpine3.17
RUN apk add libzip-dev zip libpq-dev libmcrypt-dev gmp-dev jpegoptim optipng pngquant gifsicle icu-dev git openssh curl nano \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql \
&& docker-php-ext-install zip bcmath gmp
RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
&& pecl install redis \
&& docker-php-ext-enable redis \
&& pecl install mcrypt \
&& docker-php-ext-enable mcrypt \
&& apk del pcre-dev ${PHPIZE_DEPS} \
&& rm -rf /tmp/pear
RUN docker-php-ext-configure intl && docker-php-ext-install intl
RUN apk add --update freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev libwebp-dev \
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
&& docker-php-ext-install -j$(nproc) gd \
&& apk del freetype-dev libpng-dev libjpeg-turbo-dev \
&& docker-php-ext-configure exif \
&& docker-php-ext-install exif \
&& docker-php-ext-enable exif \
&& mkdir /var/lib/php \
&& chown www-data:www-data /var/lib/php -R
RUN apk add wget nginx nodejs npm brotli nginx-mod-http-brotli
RUN mkdir -p /run/nginx
COPY docker/nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /docker
COPY ./docker /docker
RUN mkdir -p /app
COPY ./src /app
RUN sh -c "wget http://getcomposer.org/composer.phar && chmod a+x composer.phar && mv composer.phar /usr/local/bin/composer"
RUN cd /app && \
/usr/local/bin/composer install --optimize-autoloader --no-dev && \
php artisan storage:link
RUN chown -R www-data: /app
RUN chgrp -R www-data /app/storage /app/bootstrap/cache
RUN chmod -R ug+rwx /app/storage /app/bootstrap/cache
RUN sed -i 's/\r$//' /docker/startup.sh && \
chmod +x /docker/startup.sh
CMD sh /docker/startup.sh
nginx.conf
worker_processes 1;
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
keepalive_timeout 65;
server {
listen LISTEN_PORT http2 default_server;
server_name _;
root /app/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /dev/stdout;
error_log /dev/stderr;
sendfile off;
client_max_body_size 200m;
brotli on;
brotli_static on;
brotli_types *;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffering off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#include /etc/nginx/sites-enabled/*;
}
daemon off;
startup.sh
#!/bin/sh
sed -i "s,LISTEN_PORT,$PORT,g" /etc/nginx/nginx.conf
php-fpm -D
nginx
有人有什么建议,从哪里开始寻找这个问题?
added好吧,我不知道是怎么回事,ipv6在nginx中被禁用,但当我向localhost发送请求时,我的浏览器正在连接到nginx。如果我在码头的终端检查有什么用户端口80上的ipv6?
1条答案
按热度按时间xytpbqjk1#
好吧,对于任何遇到同样问题的人来说,我追踪到这个问题的原因是http2只能通过SSL连接使用。当在Google Cloud Run上运行时,他们系统的内部会照顾到这一点,但在我的本地Docker安装中却没有。