从 OVH VPS 将 nginx 日志发送到 google 云日志记录

发布于 2025-01-14 22:45:53 字数 219 浏览 2 评论 0原文

我有一个 OVH VPS,上面设置了 nginx 服务器。我正在寻找一种将 nginx 访问和错误日​​志发送到 Google Cloud Logging 服务的方法,但我能找到的所有信息都是关于从 Google Cloud VM 发送日志的。此时此刻还有可能吗?我也尝试过寻找有关将系统日志发送到 GCP 的解决方法,但也没有成功。由于我的 dotnet 服务成功将日志发送到 GCP,我认为这应该是可能的。有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画▽骨i 2025-01-21 22:45:53

在 GCP 中,与 NGINX 集成以收集连接指标和访问日志。在开始从 NGINX 收集日志之前,您需要满足一些先决条件。

  • 您必须在您的实例中安装 Ops Agent。 Ops Agent 收集 Compute Engine 实例上的日志和指标,将您的日志发送到 Cloud Logging,将指标发送到 Cloud Monitoring。如果您在 Linux SO 上使用单个 VM,则可以使用以下命令安装代理:

    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

你可以请参阅有关 Ops Agent 安装的详细信息链接

  • 您需要配置您的NGINX实例启用nginx配置文件中的stub_status模块来设置本地可访问的URL,如下例所示:

    <前><代码> http://www.example.com/status

如果您没有启用 Stub_status 模块,则可以运行以下命令来启用它:

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

请注意:127.0.0.1可以替换为真实的服务器名称,例如server_name mynginx.domain.com。

以下链接,它是在开始从 NGINX 部署收集日志之前设置所有先决条件的指南。另外,还有一个配置部署的示例

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文