If the nginx.conf file is not on the local machine, copy the file from the nginx container and save it on the local machine.
Run the following command to copy the nginx.conf file from nginx container to local machine, replacing <container_id> with your actual container ID or name
docker cp <container_id>:/etc/nginx/nginx.conf ./nginx.conf
Note: The following changes need to be made to the nginx.conf file that is passed from the local machine to the nginx container.
Step 1: Edit the nginx.conf file and comment out the existing log format and replace it with the following log_format.
log_format main '$remote_addr - $remote_user $time_iso8601 [$request_time] "$request" '
'$status $body_bytes_sent || "$request_body" || "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
Step 2: If the access_log line is commented out, Please uncomment it.
Note: If the sub_status module is available, proceed with Step 3 as outlined. However, if the module is not available, skip Step 3 and proceed directly to Step 4.
Step 3: Insert the following lines within the server module.
location /nginx-status {
stub_status on;
allow 127.0.0.1;
allow all;
}
Step 4: Download the file agent_deploy.sh from this link.
Note: We can easily download our agent directly into the nginx container, but some containers do not have commands like curl or wget and unzip, so we have to download our agent manually and mount the volume to the container.
Step 5: Login to Applicare console. Go to the Download Agent screen in the left-side menu, Download the SingleAgentLinux agent and extract it into the designated directory ApplicareSingleAgentLinux in local machine.
Step 6: Add the following command along with the command that starts the container.
Add the following command before the image name.
-v where the agent_deploy.sh file is located/agent_deploy.sh:/usr/local/agent_deploy.sh
-v ApplicareSingleAgentLinuxDirectory:/usr/local/ApplicareSingleAgentLinux
--entrypoint sh
--hostname The name which we need to add the agent in Applicare
Add the following command after the image name.
-c 'rm /var/log/nginx/access.log && touch /var/log/nginx/access.log && chown nginx:nginx /var/log/nginx/access.log && chmod +x /usr/local/agent_deploy.sh && /usr/local/agent_deploy.sh && nginx -g "daemon off;"'
Example:
docker run -d --name nginx -v /home/nginx/nginx.conf:/etc/nginx/nginx.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro -p 81:80 -v /home/nginx/agent_deploy.sh:/usr/local/agent_deploy.sh -v /root/ApplicareSingleAgentLinux:/usr/local/ApplicareSingleAgentLinux --entrypoint sh --hostname jpetstore nginx -c 'rm /var/log/nginx/access.log && touch /var/log/nginx/access.log && chown nginx:nginx /var/log/nginx/access.log && chmod +x /usr/local/agent_deploy.sh && /usr/local/agent_deploy.sh && nginx -g "daemon off;"'
Note:
rm /var/log/nginx/access.log= Deletes the file or symbolic link at /var/log/nginx/access.log
touch /var/log/nginx/access.log= Creates a new, empty file at /var/log/nginx/access.log if it doesn’t already exist.
chown nginx:nginx /var/log/nginx/access.log= Changes the ownership of /var/log/nginx/access.log to the nginx user and group.
Step 7: Once the container starts, the agent will be automatically added to the Applicare controller. To manage it, log in to the Applicare console and go to the Overview menu. Find the newly added agent, select it, and click Edit to configure as needed.
Note: If the sub_status module is available, proceed with Step 8 as outlined. However, if the module is not available, skip Step 8 and proceed directly to Step 9.
Step 8: Enable the "Add Nginx Configuration" checkbox and add the below values.
1. Log file path
2. Nginx Host
3. Nginx Port
4. Nginx Protocol
- Click the update button to save.
Step 9: Enable the "Add Nginx Configuration" checkbox and add the below values.
1. Log file path
- Click the update button to save.
Comments
0 comments
Article is closed for comments.