skip to Main Content

I need for development purpose (not for production of course), to serve my logs that are in my folder /app/logs/.

So I’ve setup a configuration like this :

    server {
        listen 80;
        server_name server-name.com;
        error_log  /app/logs/error.log warn;
        access_log /app/logs/access.log compression;
        root /var/www;

        location /info/logs/ {
            alias /app/logs/;
            autoindex on;
        }

        location / {
          // others route working
        }
    }

But everytimes i try to access to something like /app/logs/django.log using http://server-name.com/info/logs/django.log, I get a 404 and not the file I asked for.

I’ve tried many things like chmod -R 755 the entire folder or setting the folder to the user nginx use (in my case for now root, I know it’s bad), tried root or try_files but I just can’t access it…

I’ve seen many topics here and there but can’t find a clue…

Can you help me with this please ?

PS : I need the root /var/www at the beginning for others locations.

PS2 : I’m using a Docker based on Debian 9.

2

Answers


  1. Chosen as BEST ANSWER

    Ok, I've found my problem, I had a route like this :

    # Any route containing a file extension (e.g. /devicesfile.js)
    location ~ ^.+..+$ {
        try_files $uri =404;
    }
    

    And I didn't know that despite the fact it was after the first location, it would be choosen over the other location...

    Thanks for your help anyway !


  2. If you are using the standard NGINX Docker container, then the default configuration is to send the Access and Error logs to the Docker log collector. Not the standard log output for NGINX.

    The result is that your log files are most likely going to:

    file/var/lib/docker/containers/<container id>/<container id>-json.log
    on the Docker Host. Where <container id> is the long-form version of the Container Id specified when the container was setup in the first place.

    To get to the default log files you can do: docker logs <container name>

    To find the <container id> you can do: docker inspect --format '{{ .Id }}' <container name>

    If you want to customize where the log files go, then you need to create a helper Docker container that the log files can be written too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search