How Do You Get Nginx in a Docker Container to Log Web Server Activity to a Regular File inside the Container?

Problem scenario
Normally the Nginx web service logs operations (e.g., a user going to a website with a web browser).  By default Nginx Docker containers do not have good logging for web server usage.  You want regular Nginx logging inside the Docker container.  What do you do?

Solution
1.  Go inside the Docker container (e.g., docker exec -it <containerName> bash).  Go to /etc/nginx/

2.  Modify the nginx.conf file.  Find the "access_log" and "error_log" stanzas.  Change the file name to a file that does not yet exist.  Keep the location (/var/log/nginx/) the same in the stanzas.

3.  Restart the Docker container.  

4.  Now you will get regular logging of Nginx activity in the Docker container (e.g., someone accesses the web services from the front end, e.g., opening a web browser and going to the web page that the Nginx in Docker container supports).

Leave a comment

Your email address will not be published.