I have an OVH VPS with nginx server setup on it. I'm looking for a way to send nginx access and error logs to Google Cloud Logging service, but all info I could find was about sending logs from Google Cloud VMs. Is it even possible at this moment? I've tried also to find anything about sending syslog to GCP as a workaround but no luck too. Since my dotnet services succesfully send logs to GCP I suppose it should be possible. Any suggestions?
-
I have not tried this outside GCP, but I know Cloud Logging fairly well. 1) Install the Cloud Logging package: https://cloud.google.com/logging/docs/agent/logging/installation 2) Create a service account and authorize the package: https://cloud.google.com/logging/docs/agent/logging/authorization 3) There is an API and SDKs that supports writing to Cloud Logging. You could read your log files and send the contents to Cloud Logging. – John Hanley Mar 17 '22 at 19:18
-
Yeah I tried this method just before you've made your comment. It might work, but not on my server, as it's running on ubuntu 21.04 and the Cloud Logging agent supports ubuntu up to 20.04. Right now I'm trying to do some workaround sending logs from nginx to syslog-ng docker container - this way docker would work as my logging client sending logs to GCP. – Pepsko Mar 17 '22 at 19:44
-
AFAIK Cloud Logging works with Ubuntu 21.04. – John Hanley Mar 17 '22 at 20:00
-
https://cloud.google.com/logging/docs/agent/logging#supported_operating_systems It's not listed here. When I tried to install it, apt-get update would fail with ```The repository 'https://packages.cloud.google.com/apt google-cloud-logging-hirsute-all Release' does not have a Release file``` – Pepsko Mar 17 '22 at 20:12
-
This is for new users, if you are using nginx docker container, you can use docker logs driver https://docs.docker.com/config/containers/logging/gcplogs/ This is convenient. – Sachin G. Aug 20 '22 at 09:24
1 Answers
In GCP there is an integration with NGINX to collect connection metrics and access logs. There are some prerequisites that you need to accomplish before you start collecting logs from NGINX.
You must install Ops Agent in your instance . The Ops Agent collects logs and metrics on Compute Engine instances, sending your logs to Cloud Logging and your metrics to Cloud Monitoring. If you are using a single VM on a Linux SO, you can install the agent with the following command:
curl -sSO
https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
sudo bash add-google-cloud-ops-agent-repo.sh
--also-install
You can consult the details about the Ops Agent installation on this link
You will need to configure your NGINX instance enabling the stub_status module in the nginx configuration file to set up a locally reachable URL, like the following example:
http://www.example.com/status
If you don't have the stub_status module enabled, you can run the following command to enable it:
sudo tee /etc/nginx/conf.d/status.conf > /dev/null << EOF
server {
listen 80;
server_name 127.0.0.1;
location /status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location / {
root /dev/null;
}
}
EOF
sudo service nginx reload
curl http://127.0.0.1:80/status
Please note that: 127.0.0.1 can be replaced with the real server name, for example, server_name mynginx.domain.com.
All these steps are detailed in the following link, it is a guide to setup all the prerequisites before you start collecting logs from your NGINX deployment. Also, there is an example to configure your deployment

- 695
- 3
- 11