首页 > 解决方案 > 新鲜 Laravel 7 项目 LEMP 后出现 502 错误网关

问题描述

我正确地遵循了教程,但在我的本地机器上收到了 502 错误网关。我正在使用 Linux,而在教程中使用的是 Windows 10。

我不确定为什么它对我的不起作用。我从一开始就一直在使用 LAMP 堆栈,现在我计划迁移到 Dockerized LEMP 堆栈。

打开 localhost:8080 后,我收到 502 错误网关。

这是错误 502 bad gateway 的屏幕截图: 502-bad-gateway

这是我的配置/nginx/conf.d/app.conf

server {
    listen 80;
    index index.php index.html;
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param CRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

这是我的 docker-compose.yml

version: "3"
services: 
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: tomw1808/laravelproject
    container_name: app
    restart: unless-stopped
    volumes:
      - ./:/var/www
      - ./config/php/local.ini:/usr/local/etc/php/conf.d/local.ini

  webserver:
    build:
      context: .
      dockerfile: Dockerfile_Nginx
    image: tomw1808/nginx
    container_name: webserver
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www
      - ./config/nginx/conf.d:/etc/nginx/conf.d
    depends_on:
      - app

这是我的 Dockerfile_Nginx

FROM nginx:alpine

COPY ./config/nginx/conf.d/app.conf /etc/nginx/conf.d/app.conf
COPY . /var/www

这是我的 Dockerfile

FROM php:7.3-fpm-alpine

WORKDIR /var/www

RUN apk update && apk add \
    build-base \
    freetype-dev \
    libjpeg-turbo-dev \
    libpng-dev \
    libzip-dev \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd

# Install Redis Extension
RUN apk add autoconf && pecl install -o -f redis \
&&  rm -rf /tmp/pear \
&&  docker-php-ext-enable redis && apk del autoconf

# Copy config
COPY ./config/php/local.ini /usr/local/etc/php/conf.d/local.ini

RUN addgroup -g 1000 -S www && \
    adduser -u 1000 -S www -G www

USER www

COPY --chown=www:www . /var/www

RUN ["chmod", "+x", "./start_script.sh"]

EXPOSE 9000

CMD ./start_script.sh

谢谢!我一直在寻找如何解决这个错误,不幸的是无法解决这个错误。

预期的输出应该是 Fresh Laravel App 的 Welcome Page

标签: phplinuxlaraveldockernginx

解决方案


推荐阅读