V
V
Vitaly2020-11-11 21:38:21
Nginx
Vitaly, 2020-11-11 21:38:21

How to give access to images from yii2 root folder?

I am migrating a php yii2 site to a new server.
At the root of the project there is an uploads folder with images. Nginx is configured in such a way that it looks not at the root, but at the frontend / web (I don’t know if this is correct or not).
As a result, images from this uploads folder are not loaded on the site.
Please tell me how to fix this.

nginx config:

server {
        listen 80;
        listen [::]:80;
        client_max_body_size 128m;
        server_name footballcase.ru;
        root /var/www/footballcase.ru/www/frontend/web;

        access_log /var/www/footballcase.ru/logs/footballcase.ru.access;
        error_log /var/www/footballcase.ru/logs/footballcase.ru.error error;

        index index.php;

        location / {
          try_files $uri /index.php$is_args$args;
        }

        location ~ ^/assets/.*\.php$ {
          deny all;
        }

        location ~ \.php$ {
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          #fastcgi_pass 127.0.0.1:9000;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
          try_files $uri =404;
        }


Those.
< img src="/article/images/320_213_yjIPCN2EYGJ3PdU6hmGyu2KPTxy7TkF5.jpg" >

should find the image in /uploads/article/images/320_213_yjIPCN2EYGJ3PdU6hmGyu2KPTxy7TkF5.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton R., 2020-11-11
@anton_reut

https://www.yiiframework.com/doc/guide/2.0/en/stru...


Location of Resources
Resources, depending on their location, can be classified as:
source resources: resource files located along with the PHP source code that cannot be directly accessed via the Web. In order to use the original resources on the page, they must be copied to the Web directory and turned into so-called published resources. This process is called resource publishing, which is described in more detail below.
Published resources: Resource files located in a Web directory and thus can be directly accessed via the Web.
external resources: resource files located on a different web server than your application's web host.
When defining a resource bundle class, if you set the sourcePath property, this means that any resources listed using relative paths will be treated as source resources. If you do not set this property, it means that these resources are published resources (in which case you should specify basePath and baseUrl to let Yii know where the resources are located).
It is recommended to place the resources belonging to the application in the Web directory in order to avoid the unnecessary process of publishing resources. That's why the AppAsset in the previous example specifies basePath instead of sourcePath.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question