Y
Y
Yaroslav Ogloblin2019-06-29 16:55:11
Python
Yaroslav Ogloblin, 2019-06-29 16:55:11

How to correctly configure sending files from the container directly through nginx?

In one of my projects, the following situation turned out:
I have a media/folder1/ folder containing files from various service and user folders. It has a media/folder1/folder_for_nginx/ folder, which contains files that need to be given to the user directly through nginx.
I added the folder1 folder to the repository in the media folder and the folder_for_nginx folder in it, each of them contains a .gitignore file with the contents:

# Ignore everything in this directory
*
# Except this file
!.gitignore

So that everything that is added to these folders locally does not go to the repository during push.
Docker-compose and nginx were also configured:
docker-compose.yml:
project_stage:
    ...
    volumes:
      - ./folder_for_nginx:/usr/src/api/media/folder1/folder_for_nginx
...
nginx_stage:
   ...
    volumes:
      - ./folder_for_nginx:/usr/src/folder_for_nginx
...

And settings for nginx:
default.conf:
...
server {
    ...

    location /files/ {
        alias /usr/src/folder_for_nginx/;
        autoindex off;
    }
...

As a result, it turned out:
- the folder_for_nginx folder on the host turned out to be in the project root (for the docker-compose config, the api folder in the project root is the base one)
And the entire contents of the folder1 folder is deleted every time the server code is updated.
How to fix this so that the folder is in its place, and nginx has access to it and the files are not deleted?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question