Mattermost, Inc.

Proxy Config with NGINX for Mattermost and Kanboard on one server (Broken API calls in Plugins?)

Summary

I tried to install Mattermost together with Kanboard on a single server using NGINX and subpath (*/mattermost). However, API calls are not rewritten sometimes (e.g. when using file-list or other addons).

Steps to reproduce

nginx/1.14.0 (Ubuntu)
mattermost enterprise edition 5.20.2
hosted under subpath */mattermost
kanboard 1.2.13

Expected behavior

API calls are rewritten to the subpath of the mattermost installation (*/mattermost), while kanboard can be used in another path (e.g. */kanboard).

Observed behavior

While my initial nginx config seems to work so far, some plugins of the plugins I use do not rewrite their API URLs to the propper subpath (e.g. */mattermost/api/v4/(…) ). Among others, “file-list” is effected, resulting in thumbnails not showing up and download buttons that do not work.

This might be due to my attempts to configure nginx to serve as proxy and as webserver. Enclosed the nginx config I use.

upstream backend {
  server 127.0.0.1:8065;
  keepalive 32;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mattermost_cache:10m max_size=3g inactive=120m use_temp_path$

server {
   #listen 80;
   listen 80 default_server;
   listen [::]:80 default_server;
   server_name    my.ip.address;
   index index.php index.html index.htm index.nginx-debian.html;
   root         /var/www/html;

   location ~ /api/v[0-9]+/(users/)?websocket$ {
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       client_max_body_size 50M;
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Frame-Options SAMEORIGIN;
   proxy_buffers 256 16k;
   proxy_buffer_size 16k;
   client_body_timeout 60;
   send_timeout 300;
   lingering_timeout 5;
   proxy_connect_timeout 90;
   proxy_send_timeout 300;
   proxy_read_timeout 90s;
   proxy_pass http://backend;
}
 
   location /mattermost/ {
       client_max_body_size 50M;
       proxy_set_header Connection "";
       proxy_set_header Host $http_host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $scheme;
       proxy_set_header X-Frame-Options SAMEORIGIN;
       proxy_buffers 256 16k;
       proxy_buffer_size 16k;
       proxy_read_timeout 600s;
       proxy_cache mattermost_cache;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 2;
       proxy_cache_use_stale timeout;
       proxy_cache_lock on;
       proxy_http_version 1.1;
       proxy_pass http://backend;
   }
    
location / {
        try_files $uri $uri/ =404;
    }
   location ~ ^/kanboard/(?:kanboard|config.php|config.default.php) {
        deny all;
    }

        location ~* /kanboard/data {
            deny all;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        }
        location ~ /kanboard/\.ht {
            deny all;
        }
}

Maybe someone can give me a hint, whether my config or the plugin(s) are broken? Maybe the subpath is not supported?

Thanks in advance!
BR Denis

@paulrothrock Would the support team be familiar with this issue?

@denis.royer Make sure you have your Site URL configured to use the URL w/ the subdirectory, e.g. http://example.com/mattermost/. You might also need to change this:

location ~ /api/v[0-9]+/(users/)?websocket$

to this:

location ~ /mattermost/api/v[0-9]+/(users/)?websocket$