Adding Linode Longview to Nginx config via Trellis

Has anyone successfully added Linode Longview to their Trellis-provisioned server? I installed Longview and am getting basic system I/O data but am having trouble with the Longview App for Nginx and Longview App for MySQL (edit: moved to separate thread) extensions.

I added a linode-longview.conf.j2 file to trellis/nginx-includes/ containing the required configuration per the Nginx Manual Configuration instructions:

server {
  listen 127.0.0.1:80;
  server_name 127.0.0.1;
  location /nginx_status {
    stub_status on;
    allow 127.0.0.1;
    deny all;
  }
}

and ran ansible-playbook server.yml -e env=production --tags nginx-includes which successfully moved it into /etc/nginx/includes.d but when I try to access the report page I get this error:

Unable to access server status page (http://127.0.0.1/nginx_status) for Nginx: 500 Server closed connection without sending any data back

Looks like you’re using the default nginx-includes whose include is already in a server block. This adds your server block inside another server block, so it won’t work.

This include directive is located inside the primary server hook, just before the primary location block. Explore the Child templates section below for more options if this default does not satisfy your needs.

Try that child templates link, probably using the http_begin block (or a different block in that primary nginx conf) which will only include your server block once, rather than the server_before hook which could appear multiple times if you have multiple wordpress_sites (best to avoid repeating your new server block).

2 Likes

Woah, you, sir, @fullyint, are a Trellis Nginx ROCKSTAR :guitar:. Thank you!

Added:

nginx_conf: nginx-includes/linode-longview.conf.child

to trellis/group_vars/production/main.yml file and renamed linode-longview.conf.j2 to linode-longview.conf.child, adding the necessary “extends” and “block” child template elements:

{% extends 'roles/nginx/templates/nginx.conf.j2' %}

{% block http_begin -%}
    server {
        listen 127.0.0.1:80;
        server_name 127.0.0.1;
        location /nginx_status {
            stub_status on;
            allow 127.0.0.1;
            deny all;
        }
    }
{% endblock %}

…and POOF: website back from the dead and reporting NGINX stats to Linode Longview manager! :tada:

Now, on to figure out that MySQL permissions issue! :sweat_smile:

2 Likes

First of all, apologies for reopening this, but it’s the only thread regarding Linode Longview.

I was wondering if you might be kind enough to help me understand what I’m doing wrong here @gnowland

I have a deployed, up and running production site using the whole Roots stack. Following your lead, I created a file at trellis/nginx-includes/linode-longview.conf.child - creating the nginx-includes directory along the way; and pasted in:

{% extends 'roles/nginx/templates/nginx.conf.j2' %}

{% block http_begin -%}
    server {
        listen 127.0.0.1:80;
        server_name 127.0.0.1;
        location /nginx_status {
            stub_status on;
            allow 127.0.0.1;
            deny all;
        }
    }
{% endblock %}

I edited trellis/group_vars/production/main.yml and added nginx_conf: nginx-includes/linode-longview.conf.child to make the whole file like this:

mysql_root_password: "{{ vault_mysql_root_password }}" # Define this variable in group_vars/production/vault.yml
nginx_conf: nginx-includes/linode-longview.conf.child

I committed the changes to my master branch and pushed them to my repo; then ran ansible-playbook server.yml -e env=production --tags nginx-includes

At this point I went to the Linode Manager and created a new Longview instance, copied the install code, ssh into my production server, ran the code and installed the Longview Agent.

Unfortunately I get nothing - not even basic reporting. The Longview page for this agent just keeps spinning and waiting for connection. Could this be something to do with a port not being open?

While on the server, I checked the /etc/nginx directory and I don’t see any includes.d directory there either.

Just for the hell of it I did try a complete reprovision, but that changes nothing. Does anyone have any ideas what I could try?

Many thanks!


UPDATE

So it appears that the conf inside trellis/nginx-includes/linode-longview.conf.child is indeed being included in the /etc/nginx/nginx.conf on the server, and not placed in a includes.d directory, so at least its there. Does anyone know why Longview may still be be unable to connect?

http {
  server {
        listen 127.0.0.1:80;
        server_name 127.0.0.1;
        location /nginx_status {
            stub_status on;
            allow 127.0.0.1;
            deny all;
        }
    }

UPDATE

OK, I figured this out. I’ll lay it out from the start as I understand it for anyone else stuck with this. In this case, I’m adding Longview to my Production server.

  1. Create a new file at trellis/nginx-includes/all/linode-longview.conf.child, creating any missing directories as required.

  2. Paste the following into that file:

{% extends 'roles/nginx/templates/nginx.conf.j2' %}

{% block http_begin -%}
    server {
        listen 127.0.0.1:80;
        server_name 127.0.0.1;
        location /nginx_status {
            stub_status on;
            allow 127.0.0.1;
            deny all;
        }
    }
{% endblock %}
  1. Edit trellis/group_vars/production/main.yml and add nginx_conf: nginx-includes/linode-longview.conf.child at the end, to make it like so:
mysql_root_password: "{{ vault_mysql_root_password }}" # Define this variable in group_vars/production/vault.yml
nginx_conf: nginx-includes/all/linode-longview.conf.child
  1. Commit and push the changes to your repo, and reprovision the Production server ansible-playbook server.yml -e env=production

  2. Visit the Linode Manager and create a new instance of Longview. Copy the install code.

  3. SSH into your production server, and paste the installation command in and run it. If you are asked if you would like it to autoconfigure, select ‘No’.

  4. Restart nginx systemctl restart nginx.service

I hope that works for you!

2 Likes