简体   繁体   中英

Send nginx logs to google cloud logging from OVH VPS

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 do.net services succesfully send logs to GCP I suppose it should be possible. Any suggestions?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM