LoginSignup
5
1

More than 5 years have passed since last update.

mastodonが動いているサーバーにnetdataを相乗りさせた際のnginxの設定

Last updated at Posted at 2017-04-25

TL;DR

動作環境

  • Ubuntu16.04LTS
  • docker&nginx

参考リンク

手順

  • リンクを参考にnetdataをインストールし19999ポートで動作していることを確認
  • mastodonのconfファイルに以下のpatchをあてる
# diff -u mstdn.conf.org mstdn.conf
--- mstdn.conf.org      2017-04-25 16:45:27.205512141 +0000
+++ mstdn.conf  2017-04-25 16:03:56.388854481 +0000
@@ -12,6 +12,11 @@
     location / { return 301 https://$host$request_uri; }
 }

+upstream netdata {
+    server 127.0.0.1:19999;
+    keepalive 64;
+}
+
 server {
     listen 443 ssl;
     listen [::]:443 ssl;
@@ -87,5 +92,29 @@
         tcp_nodelay on;
     }

+    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 *;
+    }
     error_page 500 501 502 503 504 /500.html;
 }
  • これでhttps://{自ドメイン}/netdata にアクセスするとnetdataが表示されるようになりました!!
    • ※mastodon自体が /netdata って名前を使用した際はよしなにしてください

netdataだけBasic認証かける

  • netdata自体の認証機構はまだ議論中のようでさしあたってBasic認証をかけるにはさらに以下のpatchをあてるといい
# diff -u mstdn.conf.basic mstdn.conf
--- mstdn.conf    2017-04-25 16:54:52.965571325 +0000
+++ mstdn.conf.basic  2017-04-25 16:03:56.388854481 +0000
@@ -97,6 +97,9 @@
     }

     location ~ /netdata/(?<ndpath>.*) {
+        auth_basic "Protected";
+        auth_basic_user_file /etc/nginx/.htpasswd;
+
         proxy_redirect off;
         proxy_set_header Host $host;

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1