首页 > 解决方案 > 启动 laravel swagger 时重定向到正确的 docker 主机的问题

问题描述

我在 Laravel 5.5 和带有 nginx 配置的 docker 上安装和使用我的 Laravel-swagger 包时遇到问题。问题是,当我尝试使用已安装的 swagger (https://127.0.0.1:8080/api/documentation /127.0.0.1/docs/asset/swagger-ui.css?v=1f524b0bbfd05a62b996252847139c9d 在此处输入图像描述

我试图通过更改我的 docker 和 nginx 配置文件的配置来解决这个问题。以下是一些例子:

docker-compose.yaml

      nginx:
        container_name: ${SERVICE_NAME}-nginx
        build:
            context: ./docker/nginx/
            dockerfile: Dockerfile
            args:
                USER_ID: $USER_ID
                GROUP_ID: $GROUP_ID
        ports:
            - "$CONTAINER_PORT_NGINX:8080"
        depends_on: 
            - php
        environment:
            TZ: 'Europe/Moscow'
        networks:
            - default
        # read_only: true
        tmpfs:
            - /var/cache/nginx
            - /var/lib/nginx
            - /var/lib/nginx/logs/
            - /var/tmp/nginx/proxy
            - /var/tmp/nginx/fastcgi
            - /var/tmp/nginx/client_body
            - /var/tmp/nginx/uwsgi
            - /var/tmp/nginx/scgi
            - /run
            - /tmp
        restart: unless-stopped
        stdin_open: true
        tty: true
        volumes:
            - .:/var/www/html:cached

Dockerfile

FROM alpine:3.10

ARG USER_ID
ARG GROUP_ID

RUN apk --update --no-cache add nginx shadow

COPY nginx.conf /etc/nginx/
COPY default.conf /etc/nginx/conf.d/default.conf

RUN groupmod -g ${GROUP_ID} www-data && adduser -D -g '' -u ${USER_ID} -G www-data www-data 

CMD ["nginx"]

EXPOSE 8080

默认.conf

upstream php-upstream {
    server php:9000; 
}

server {
    listen                          8080;
    server_name                     localhost;
    root                            /var/www/html/public;
    index                           index.php index.html index.htm;
    charset                         utf-8;

    location / {
        absolute_redirect           on;
        try_files                   $uri $uri/ /index.php?$query_string;
    }

    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|txt|mp3|js|html)$
    {
        expires                     7d;
        access_log                  off;
        add_header Cache-Control    "public";
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_read_timeout        600;
        include                     fastcgi_params;
        fastcgi_index               index.php;
        fastcgi_param               SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param               HTTPS    off;
        fastcgi_pass                php-upstream;
        fastcgi_param               HTTP_HOST    $host;
    }

    error_log /var/log/nginx/site_error.log;
    access_log /var/log/nginx/site_access.log;

    # ---REM--- send_timeout 300;

    # Disable logging for favicon.ico
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Disable logging for robots.txt
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~* /\. {
        deny all;
    }
}

但没有什么能帮到我,我在 docker 和配置 nginx 应用程序方面不是那么强,所以我真的需要帮助来解决这个问题。谢谢

标签: laraveldockernginxswagger

解决方案


推荐阅读