Failure to run behind Nginx

Environment

Ubuntu 21.04 hirsute, Nginx 1.21.1, Netdata v1.31.0-132-nightly

Problem/Question

I suspect this is a problem stemming from my own inexperience with nginx but i followed the steps in Running Netdata behind Nginx | Learn Netdata about running netdata in a subfolder behind an existing host but i keep getting errors like this in developer console
image
or this
image.psd
image.psd(1)

my nginx configuration file for netdata is stored in /etc/nginx/sites-available/DOMAIN and is this:

upstream netdata {
    server 127.0.0.1:19999;
    keepalive 64;
}

server {
    listen 80;
    # uncomment the line if you want nginx to listen on IPv6 address
    #listen [::]:80;

    # the virtual host name of this subfolder should be exposed
    #server_name netdata.example.com;

    location = /netdata {
        return 301 /netdata/;
    }

    location ~ /netdata/(?<ndpath>.*) {
        proxy_redirect off;
        proxy_set_header Host $host;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_pass_request_headers on;
        proxy_set_header Connection "keep-alive";
        proxy_store off;
        proxy_pass http://netdata/$ndpath$is_args$args;

        gzip on;
        gzip_proxied any;
        gzip_types *;
    }
}

Will provide more details as needed

Hi, not an Nginx specialist, just copying the location I used on one of my servers. It worked for me.

location /netdata/ {
  rewrite ^/netdata(/.*)$ $1 break;
  proxy_pass http://localhost:19999;
}

Ok, I tested our documentation config. Works without problems (http://HOSTNAME/netdata).

[ilyam@pc nginx]$ nginx -v
nginx version: nginx/1.20.1
[ilyam@pc nginx]$ grep -v "#" nginx.conf | grep -v -e '^$'
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream netdata {
        server 127.0.0.1:19999;
        keepalive 64;
    }
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
        location = /netdata {
            return 301 /netdata/;
        }
        location ~ /netdata/(?<ndpath>.*) {
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_pass_request_headers on;
            proxy_set_header Connection "keep-alive";
            proxy_store off;
            proxy_pass http://netdata/$ndpath$is_args$args;
            gzip on;
            gzip_proxied any;
            gzip_types *;
        }
    }
}

0 ~ $ curl http://pc/netdata/api/v1/info
{
	"version": "v1.31.0-132-g6a201507a",
	"uid": "f2538ada-e937-11eb-9bb6-4cedfb3652ae",
	"mirrored_hosts": [
		"pc"
	],
	"mirrored_hosts_status": [
		{ "guid": "f2538ada-e937-11eb-9bb6-4cedfb3652ae", "reachable": true, "hops": 0, "claim_id": null }
	],
	"alarms": {
		"normal": 0,
		"warning": 1,
		"critical": 0
	},
	"os_name": "Manjaro Linux",
...

Thank you!

I will be testing this out in a bit. Though I did try your location configuration on my DOMAIN sites-available config which led me to a 404 page which makes me think I did something wrong in the initial setup.

So after completely reinstalling nginx and resetting all its configs to default and basically copy pasting the nginx conf you provided. It finally worked.

Now to test slowly.

Update:
After using certbot to install the ssl certificate. It then returned a 404 error.

I think i have found the problem.

I don’t exactly know how nginx does ssl certificates but this code only seems to work on one server block and cannot work on the rest.

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
	listen 443 ssl; # managed by Certbot
	ssl_certificate /etc/letsencrypt/live/DOMAIN/fullchain.pem; # managed by Certbot
	ssl_certificate_key /etc/letsencrypt/live/DOMAIN/privkey.pem; # managed by Certbot
	include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
	ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

Unfortunately, this does make it so that the server block without this will 404 for some reason.
I do not know how this works, but for now i have disabled https to make things work