Search code examples
dockernginxloggingdockerfileconfiguration-files

How to modify nginx access and error log locations with dockerfile?


I am running nginx in a docker container. I have to RELOCATE the nginx log files from /var/log/nginx/error.log and /var/log/nginx/access.log to different locations. For this I need to modify the /etc/nginx/nginx.conf file in my docker image. What can I mention in my dockerfile to make this modification?

I do not want to re-write the nginx.conf file with commands like echo.


Solution

  • You don't need to rewrite using echos, it's easier than that.

    • Change the file nginx.conf to your needs.
    • Put it next to the Dockerfile
    • Add the following instruction to your Dockerfile: COPY nginx.conf /etc/nginx/nginx.conf