[solved] Docker Compose Mattermost with nginx Proxy dont work

Summary

Mattermost docker image with nginx proxy dont work

Expected behavior

i install mattermost with docker-compose with this config =

version: “2”

services:

db:
build: db
restart: unless-stopped
volumes:
- ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=pw
- POSTGRES_DB=mattermost
# uncomment the following to enable backup
# - AWS_ACCESS_KEY_ID=XXXX
# - AWS_SECRET_ACCESS_KEY=XXXX
# - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
# - AWS_REGION=us-east-1

app:
build:
context: app
# comment out 2 following lines for team edition
# args:
# - edition=team
restart: unless-stopped
volumes:
- ./volumes/app/mattermost/config:/mattermost/config:rw
- ./volumes/app/mattermost/data:/mattermost/data:rw
- ./volumes/app/mattermost/logs:/mattermost/logs:rw
- /etc/localtime:/etc/localtime:ro
environment:
# set same as db credentials and dbname
- MM_USERNAME=user
- MM_PASSWORD=pw
- MM_DBNAME=mattermost
# in case your config is not in default location
#- MM_CONFIG=/mattermost/config/config.json
ports:
- “8000:443”
links:
- db:db

i bring it up wit docker-compuse up -d

my nginx proxy config file =

upstream mattermost {
server 127.0.0.1:8000;
}

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

server {
server_name mydomain;

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;
proxy_read_timeout 600s;
proxy_pass http://mattermost;
}

location / {
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_pass http://mattermost;
}

when i go to the site its come nginx bad gateway. i read many instruction but i dont know where is my failure.

in the nginx log file =

connect() failed (111: Connection refused) while connecting to upstream, client:

Thanks Felix

Hi @Felix,

Were you following the “How do I setup an NGINX proxy with the Mattermost Docker installation?” section of this doc https://docs.mattermost.com/install/config-proxy-nginx.html?

first thanks for you reply.

i see the link and i read the link, but is the doc real or outdatet.

i read thats mattermost 5… the port is now 8000 and not 8065. The docker app container say also 8000. So now i ám confused.
Also when i expose ports in the config file, always is come thats blocked not ended.

To my understand.

Port is 8065?
I bind my nginx proxy to 127.0.0.1:8065?

sry too much frustration and i think it is my fault :slight_smile:

@pichouk Do you know more about this issue?

Hi @Felix,

Why did you bind your app container port 8000 to 443 ?

ports:
- “8000:443”

I think you should use port 8000 instead. Mattermost service is not listening on port 443 if you use the Docker image.

Hi pichouk,

that expose was from one test. I set it now again from scratch but also , ist has always error 500.

i post you my settings:

ubuntu , nginx, docker

docker-compose.xml

version: “2”

services:

db:
build: db
read_only: true
restart: unless-stopped
volumes:
- ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
- POSTGRES_USER=mmuser
- POSTGRES_PASSWORD=mmuser_password
- POSTGRES_DB=mattermost
# uncomment the following to enable backup
# - AWS_ACCESS_KEY_ID=XXXX
# - AWS_SECRET_ACCESS_KEY=XXXX
# - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
# - AWS_REGION=us-east-1

app:
build:
context: app
# uncomment following lines for team edition or change UID/GID
# args:
# - edition=team
# - PUID=1000
# - PGID=1000
restart: unless-stopped
volumes:
- ./volumes/app/mattermost/config:/mattermost/config:rw
- ./volumes/app/mattermost/data:/mattermost/data:rw
- ./volumes/app/mattermost/logs:/mattermost/logs:rw
- ./volumes/app/mattermost/plugins:/mattermost/plugins:rw
- ./volumes/app/mattermost/client-plugins:/mattermost/client/plugins:rw
- /etc/localtime:/etc/localtime:ro
environment:
# set same as db credentials and dbname
- MM_USERNAME=mmuser
- MM_PASSWORD=mmuser_password
- MM_DBNAME=mattermost
# in case your config is not in default location
#- MM_CONFIG=/mattermost/config/config.json


nginx site config

upstream mattermost {
server 127.0.0.1:8000;
}

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

server {
server_name xxx;

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;
proxy_read_timeout 600s;
proxy_pass http://mattermost;
}

location / {
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_pass http://mattermost;
}


docker ps:

mattermost-docker_db 5432/tcp
mattermost-docker_app 8000/tcp

i have delete the web config in docker-compose, because nginx proxy.

in my nginx log file:

failed (111: Connection refused) while connecting to upstream,

What did I miss? Thank you very much for your time and help. Felix

1 Like

My debt and excuse me for taking up your time. I set in the nginx the docker ip from mattermost_app and the the upstream is correct.

Thanks again for trying to help me! Felix

You should keep this part I think :

ports:
  - “8000:8000”

I guess you can have something working with this docker-compose.yml

version: “2”
services:
  db:
    build: db
    read_only: true
    restart: unless-stopped
    volumes:
      - ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
    environment:
      - POSTGRES_USER=mmuser
      - POSTGRES_PASSWORD=mmuser_password
      - POSTGRES_DB=mattermost

  app:
    build:
      context: app
    restart: unless-stopped
    volumes:
      - ./volumes/app/mattermost/config:/mattermost/config:rw
      - ./volumes/app/mattermost/data:/mattermost/data:rw
      - ./volumes/app/mattermost/logs:/mattermost/logs:rw
      - ./volumes/app/mattermost/plugins:/mattermost/plugins:rw
      - ./volumes/app/mattermost/client-plugins:/mattermost/client/plugins:rw
      - /etc/localtime:/etc/localtime:ro
    environment:
      - MM_USERNAME=mmuser
      - MM_PASSWORD=mmuser_password
      - MM_DBNAME=mattermost
    ports:
      - “8000:8000”

Thanks, it works now when i bind the nginx proxy to the docker ip from the mattermost app with port 8000.

But i have one question, when i uncomment the arg line with the edition or i wrote the port line, docker-compose write a failure:

ERROR: yaml.parser.ParserError: while parsing a block mapping
in “./docker-compose.yml”, line 24, column 7
expected , but found ‘’
in “./docker-compose.yml”, line 26, column 8

args:
- edition=team

or when i set the ports as in your example.

I think it’s just because I made a bad copy paste. I wrote instead of ".

If you write

ports:
  - "80:80"

I think it will works better :slight_smile:

I’ve still got the wrong one.

my docker.yml


version: “2”

services:

db:
build: db
read_only: true
restart: unless-stopped
volumes:
- ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
- POSTGRES_USER=xxx
- POSTGRES_PASSWORD=xxx
- POSTGRES_DB=xxx
# uncomment the following to enable backup
# - AWS_ACCESS_KEY_ID=XXXX
# - AWS_SECRET_ACCESS_KEY=XXXX
# - WALE_S3_PREFIX=s3://BUCKET_NAME/PATH
# - AWS_REGION=us-east-1

app:
build:
context: app
# uncomment following lines for team edition or change UID/GID
args:
- edition=team
# - PUID=1000
# - PGID=1000
restart: unless-stopped
volumes:
- ./volumes/app/mattermost/config:/mattermost/config:rw
- ./volumes/app/mattermost/data:/mattermost/data:rw
- ./volumes/app/mattermost/logs:/mattermost/logs:rw
- ./volumes/app/mattermost/plugins:/mattermost/plugins:rw
- ./volumes/app/mattermost/client-plugins:/mattermost/client/plugins:rw
- /etc/localtime:/etc/localtime:ro
environment:
# set same as db credentials and dbname
- MM_USERNAME=xxx
- MM_PASSWORD=xxx
- MM_DBNAME=xxx
ports:
- “8000:8000”
# in case your config is not in default location
#- MM_CONFIG=/mattermost/config/config.json

I become the same issues by the edition and the port parameter:

expected , but found ‘?’

its run now :). thanks for all your support.

1 Like