Symfony / liip_imagine: разрешение пути изображения приводит к 404 - PullRequest
1 голос
/ 11 марта 2020

Конфигурация сервера

Symfony 4.4.2
Apache 2.4.29
PHP: 7.3
Hosting: AWS LightSail

Я использую пакет liip_imagine для обработки загруженных изображений и отображения их в шаблонах веточек с помощью asset(). К сожалению, URL изображений разрешается до 404, и я не могу понять, почему.

Вот соответствующий шаблон ветки:

<div class="col">
  <p>{{ 'Current image' | trans }}</p>
      {% if module.image != '' %}
           <img style="width: 180px;" src="{{ asset(module.image | imagine_filter('learningModuleImage')) }}" alt="">
       {% endif %}
</div>

Я проверил это:

  • файлы правильно загружены в папку / public / upload.
  • module.image содержит имя и расширение хэша изображения: da305b9a0fee3eb7bdc5bfc9b64e88ff.jpeg
  • Реальный URL: /public/upload/da305b9a0fee3eb7bdc5bfc9b64e88ff.jpeg
  • Сгенерированный URL: https://domain.tld/media/cache/learningModuleImage/da305b9a0fee3eb7bdc5bfc9b64e88ff.jpeg

  • Конфигурация:


liip_imagine:
    loaders:
        default:
            filesystem:
                data_root:
                    - "%kernel.project_dir%/public/upload"
                    - "%kernel.project_dir%/public/assets/img"

    resolvers:
        default:
            web_path:
                web_root: "%kernel.project_dir%/public/upload"
                cache_prefix: media/cache

    filter_sets:
        cache: ~
        learningModuleImage:
            filters:
                downscale:
                    max: [512, 512]
        profile:
            filters:
                downscale:
                    max: [512, 512]

        # the name of the "filter set"
        thumb:
            # adjust the image quality to 75%
            # quality: 75

            # list of transformations to apply (the "filters")
            filters:
                # create a thumbnail: set size to 120x90 and use the "outbound" mode
                # to crop the image when the size ratio of the input differs
                thumbnail: { size: [128, 128], mode: outbound }
                # create a 2px black border: center the thumbnail on a black background
                # 4px larger to create a 2px border around the final image
                # background: { size: [124, 94], position: center, color: '#000000' }

Я также проверил виртуальный хост:

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName domain.tld

        DocumentRoot /var/www/project/public
        DirectoryIndex /index.php

        <Directory /var/www/project/public>
                AllowOverride All
                Order Allow,Deny
                Allow from All
                Options -MultiViews
                Require all granted

                FallbackResource /index.php
         </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error-project.log
        CustomLog ${APACHE_LOG_DIR}/access-project.log combined

        # Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateFile /etc/letsencrypt/live/domain.tld/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

1 Ответ

0 голосов
/ 11 марта 2020

Я решил это!

Вот рабочая конфигурация. Спасибо @MaulikParmar за ваш совет!


liip_imagine:
    loaders:
        default:
            filesystem:
                data_root:
                    - "%kernel.project_dir%/public/upload"
                    - "%kernel.project_dir%/public/assets/img"

    resolvers:
        default:
            web_path:
                web_root: "%kernel.project_dir%/public"
                cache_prefix: media/cache

    filter_sets:
        cache: ~
        learningModuleImage:
            cache: default
            filters:
                downscale:
                    max: [512, 512]
        profile:
            filters:
                downscale:
                    max: [512, 512]

        # the name of the "filter set"
        thumb:
            # adjust the image quality to 75%
            # quality: 75
            cache: default
            # list of transformations to apply (the "filters")
            filters:
                # create a thumbnail: set size to 120x90 and use the "outbound" mode
                # to crop the image when the size ratio of the input differs
                thumbnail: { size: [128, 128], mode: outbound }
                # create a 2px black border: center the thumbnail on a black background
                # 4px larger to create a 2px border around the final image
                # background: { size: [124, 94], position: center, color: '#000000' }
...