TandoorRecipes / recipes

Application for managing recipes, planning meals, building shopping lists and much much more!
https://docs.tandoor.dev
Other
5.3k stars 555 forks source link

504 Gateway Time-out on Synology NAS #427

Closed puckzuck closed 3 years ago

puckzuck commented 3 years ago

Version

Please provide your current version (can be found on the system page since v0.8.4) Version:

Issue

I tried to set up Tandoor Recipes with the Docker/Synology Documentation and always get a 504 Gateway-Timeout when accessing. Tried the same process with a Raspberry Pi 4, and the same error occured.

.env

Please include your .env config file (make sure to remove/replace all secrets)

# only set this to true when testing/debugging
# when unset: 1 (true) - dont unset this, just for development
DEBUG=0

# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
ALLOWED_HOSTS=*

# random secret key, use for example `base64 /dev/urandom | head -c50` to generate one
SECRET_KEY=SECRETXXX

# your default timezone See https://timezonedb.com/time-zones for a list of timezones
TIMEZONE=Europe/Berlin

# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
DB_ENGINE=django.db.backends.postgresql
POSTGRES_HOST=db_recipes
POSTGRES_PORT=5432
POSTGRES_USER=djangouser
POSTGRES_PASSWORD=PASSXXX
POSTGRES_DB=djangodb

# the default value for the user preference 'fractions' (enable/disable fraction support)
# default: disabled=0
FRACTION_PREF_DEFAULT=0

# the default value for the user preference 'comments' (enable/disable commenting system)
# default comments enabled=1
COMMENT_PREF_DEFAULT=1

# Users can set a amount of time after which the shopping list is refreshed when they are in viewing mode
# This is the minimum interval users can set. Setting this to low will allow users to refresh very frequently which
# might cause high load on the server. (Technically they can obviously refresh as often as they want with their own scripts)
SHOPPING_MIN_AUTOSYNC_INTERVAL=5

# Default for user setting sticky navbar
#STICKY_NAV_PREF_DEFAULT=1

# If staticfiles are stored at a different location uncomment and change accordingly
# STATIC_URL=/static/

# If mediafiles are stored at a different location uncomment and change accordingly
# MEDIA_URL=/media/

# Serve mediafiles directly using gunicorn. Basically everyone recommends not doing this. Please use any of the examples
# provided that include an additional nxginx container to handle media file serving.
# If you know what you are doing turn this back on (1) to serve media files using djangos serve() method.
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
GUNICORN_MEDIA=0

# allow authentication via reverse proxy (e.g. authelia), leave off if you dont know what you are doing
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
# when unset: 0 (false)
REVERSE_PROXY_AUTH=0

# allows you to setup OAuth providers
# see docs for more information https://vabene1111.github.io/recipes/features/authentication/
# SOCIAL_PROVIDERS = allauth.socialaccount.providers.github, allauth.socialaccount.providers.nextcloud,

docker-compose.yml

When running with docker compose please provide your docker-compose.yml

version: "3"
services:
  db_recipes:
    restart: always
    image: postgres:11-alpine
    volumes:
      - ./postgresql:/var/lib/postgresql/data
    env_file:
      - ./.env

  web_recipes:
    image: vabene1111/recipes
    restart: always
    env_file:
      - ./.env
    volumes:
      - staticfiles:/opt/recipes/staticfiles
      - nginx_config:/opt/recipes/nginx/conf.d
      - ./mediafiles:/opt/recipes/mediafiles
    depends_on:
      - db_recipes

  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    ports:
      - 8001:80
    env_file:
      - ./.env
    depends_on:
      - web_recipes
    volumes:
      - nginx_config:/etc/nginx/conf.d:ro
      - staticfiles:/static
      - ./mediafiles:/media

volumes:
  nginx_config:
  staticfiles:
vabene1111 commented 3 years ago

that is intereseting, your files look correct ...

can you pot the output of docker-compose logs -f when getting a timeout

puckzuck commented 3 years ago

The Synology NAS gives me this:

Attaching to recipes_nginx_recipes_1, recipes_web_recipes_1, recipes_db_recipes_1 nginx_recipes_1 | WARNING: no logs are available with the 'db' log driver web_recipes_1 | WARNING: no logs are available with the 'db' log driver db_recipes_1 | WARNING: no logs are available with the 'db' log driver

But the Raspberry Pi gives more information. The log file attached is full of errors... :-/

recipe.log

vabene1111 commented 3 years ago

ok i am not sure what you are doing wrong as the configs you provide above are correct but the logs show issues with the connection from the python webserver to the database and possible also the nginx container. I am not sure if you have any sepecial network configurations or anything but dont really know what is wrong here

puckzuck commented 3 years ago

I got no special network configuration that I'm aware of. Wired connections to AVM Fritzbox router, router runs DHCP and DNS. Other docker-contained services run as expected.

I just installes Docker for Windows on my PC and used the same docker-compose.yml and .env file, without success when trying to access http://localhost:8001.

I also used fresh docker-compose.yml and .env files to rule out some weird typo that I might have put in there.

I noticed that the docker/postgresql folder gets owned by user "70". I tried chown it to my dockeruser and to my admin user, but it will always change back to "70" with 700 permissions. Is that normal, or could it be part of the issue? Happens both on Synology and on RPI.

vabene1111 commented 3 years ago

I honestly have never really looked at the permissions. From what i could gather running docker containers as root is fine so i always do it this way. I never had any permission related issues.

Just to make sure i understood you correctly, you have followed the install instructions exactly wihtout modifying anything on your windows machine and it still does not work ?

puckzuck commented 3 years ago

Here is a step-by-step of what I did now:

  1. I freshly installed Docker for Windows and created a docker folder

  2. I made sure there were no docker images at all present on my machine

  3. I then created a "recipes" folder inside the docker folder

  4. I used the exact text as posted above for my .env and docker-compose.yml files inside the recipes folder which gave me the following output when running docker-compose up -d

    docker\recipes> docker-compose up -d Creating network "recipes_default" with the default driver Pulling db_recipes (postgres:11-alpine)... 11-alpine: Pulling from library/postgres ba3557a56b15: Pull complete 0dae7ecc9e7b: Pull complete e47d778d7c5a: Pull complete dfd12115893a: Pull complete f8d09f2ac600: Pull complete a6f5d07c61c3: Pull complete c42ebe7c7817: Pull complete 7b262cc79324: Pull complete cef1c9ce61b5: Pull complete Digest: sha256:3d28d3d9295bf03e1a6fba1b335dfc1560501aa678c6aa74f18849111721e886 Status: Downloaded newer image for postgres:11-alpine Pulling web_recipes (vabene1111/recipes:)... latest: Pulling from vabene1111/recipes ba3557a56b15: Already exists 54b0d889b94a: Pull complete ef397b6c435a: Pull complete 7ba08b745588: Pull complete a287fd401f0c: Pull complete d834e0d696a0: Pull complete c645ad774e60: Pull complete 25930d3436e8: Pull complete a09b21798785: Pull complete d38bcdfd0574: Pull complete Digest: sha256:3f896175df02a4b4d62a4bb23a96ebe00d3ea22c2a2f9c3dd57fe50fd0cc395a Status: Downloaded newer image for vabene1111/recipes:latest Pulling nginx_recipes (nginx:mainline-alpine)... mainline-alpine: Pulling from library/nginx ba3557a56b15: Already exists 1a18b9f93d41: Pull complete 38ceab6c6432: Pull complete 6104f3bd82cc: Pull complete 750e0e12d70c: Pull complete d7c38a871210: Pull complete Digest: sha256:14536d83ca3128923ee7c2f7f4f285e023abd40f3ccdc8911f56cd4119558506 Status: Downloaded newer image for nginx:mainline-alpine Creating recipes_db_recipes_1 ... done Creating recipes_web_recipes_1 ... done Creating recipes_nginx_recipes_1 ... done

  5. I ran docker-compose logs -f > recipe.log

  6. I waited a few minutes, then tried to access http://localhost:8001 on the same windows machine using Firefox and Edge, and now I both times get a Server Error (500)

  7. I attached the logfile: recipe.log

vabene1111 commented 3 years ago

ok thanks, the last log you posted definitely shows that the recipes container is not able to access the database.

i dont really know why because your env file looks correct but this is definitly what the logs say and also might be a reason for the 504.

maybe you could exec into the container and verify if the environment variables are loaded correctly. But since the same issue is happening on windows and linux that sounds unlikely as the cause of the error

puckzuck commented 3 years ago

So now the weirdest thing happend. I have not touched my Windows PC yesterday as I was not at home, it was shut down. Today I started up the docker-for-windows on that machine and wanted to exec into the containers. I tried http://localhost:8001 once more and it greeted me with the setup page. Nice. :-)

The NAS and the Pi still do not work. I checked for the environment variables, and they all show up when running env in the container shell. I even tried copying the whole folder from the windows setup to either the NAS or PI, but that doesn't change anything, stll getting the 504. Looking around with the mounted files/folders, environment variables, ifconfigdata, ps ax, I was not really able to find something off. But I did not know what to look for exactly...

BUT: I found out how to export the Synology Logs. Seems like it is not the same problem as with the Pi-Logs.

db:

date stream content
2021-02-22 16:27:30 stderr 2021-02-22 16:27:30.784 UTC [1] LOG:  database system is ready to accept connections
2021-02-22 16:27:30 stderr 2021-02-22 16:27:30.650 UTC [22] LOG:  database system was shut down at 2021-02-22 16:25:51 UTC
2021-02-22 16:27:30 stderr 2021-02-22 16:27:30.254 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-02-22 16:27:29 stderr 2021-02-22 16:27:29.987 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2021-02-22 16:27:29 stderr 2021-02-22 16:27:29.987 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2021-02-22 16:27:29 stdout  
2021-02-22 16:27:29 stdout PostgreSQL Database directory appears to contain a database; Skipping initialization
2021-02-22 16:27:29 stdout  

web:

date stream content
2021-02-22 16:29:53 stderr [2021-02-22 16:29:53 +0000] [17] [INFO] Booting worker with pid: 17
2021-02-22 16:29:53 stderr [2021-02-22 16:29:53 +0000] [1] [INFO] Using worker: sync
2021-02-22 16:29:53 stderr [2021-02-22 16:29:53 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
2021-02-22 16:29:53 stderr [2021-02-22 16:29:53 +0000] [1] [INFO] Starting gunicorn 20.0.4
2021-02-22 16:29:53 stdout Done
2021-02-22 16:29:53 stdout 1 static file copied to '/opt/recipes/staticfiles', 516 unmodified, 984 post-processed.
2021-02-22 16:29:53 stdout  
2021-02-22 16:29:46 stdout js-reverse file written to /opt/recipes/cookbook/static/django_js_reverse
2021-02-22 16:29:44 stderr  
2021-02-22 16:29:44 stderr TCP/IP connections on port 5432?
2021-02-22 16:29:44 stderr Is the server running on host "db_recipes" (192.168.96.2) and accepting
2021-02-22 16:29:44 stderr django.db.utils.OperationalError: could not connect to server: Operation timed out
2021-02-22 16:29:44 stderr conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/psycopg2/init.py", line 127, in connect
2021-02-22 16:29:44 stderr connection = Database.connect(**conn_params)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
2021-02-22 16:29:44 stderr return func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2021-02-22 16:29:44 stderr self.connection = self.get_new_connection(conn_params)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
2021-02-22 16:29:44 stderr return func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2021-02-22 16:29:44 stderr self.connect()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
2021-02-22 16:29:44 stderr raise dj_exc_value.with_traceback(traceback) from exc_value
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in exit
2021-02-22 16:29:44 stderr self.connect()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
2021-02-22 16:29:44 stderr return func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2021-02-22 16:29:44 stderr self.ensure_connection()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 235, in _cursor
2021-02-22 16:29:44 stderr return self._cursor()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 259, in cursor
2021-02-22 16:29:44 stderr return func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2021-02-22 16:29:44 stderr with self.connection.cursor() as cursor:
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 55, in has_table
2021-02-22 16:29:44 stderr if self.has_table():
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
2021-02-22 16:29:44 stderr self.applied_migrations = recorder.applied_migrations()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 216, in build_graph
2021-02-22 16:29:44 stderr self.build_graph()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in init
2021-02-22 16:29:44 stderr self.loader = MigrationLoader(self.connection)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in init
2021-02-22 16:29:44 stderr executor = MigrationExecutor(connection, self.migration_progress_callback)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 92, in handle
2021-02-22 16:29:44 stderr res = handle_func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/management/base.py", line 85, in wrapped
2021-02-22 16:29:44 stderr output = self.handle(*args, **options)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
2021-02-22 16:29:44 stderr self.execute(*args, **cmd_options)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
2021-02-22 16:29:44 stderr self.fetch_command(subcommand).run_from_argv(self.argv)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/management/init.py", line 395, in execute
2021-02-22 16:29:44 stderr utility.execute()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/management/init.py", line 401, in execute_from_command_line
2021-02-22 16:29:44 stderr execute_from_command_line(sys.argv)
2021-02-22 16:29:44 stderr File "manage.py", line 15, in 
2021-02-22 16:29:44 stderr Traceback (most recent call last):
2021-02-22 16:29:44 stderr  
2021-02-22 16:29:44 stderr The above exception was the direct cause of the following exception:
2021-02-22 16:29:44 stderr  
2021-02-22 16:29:44 stderr  
2021-02-22 16:29:44 stderr TCP/IP connections on port 5432?
2021-02-22 16:29:44 stderr Is the server running on host "db_recipes" (192.168.96.2) and accepting
2021-02-22 16:29:44 stderr psycopg2.OperationalError: could not connect to server: Operation timed out
2021-02-22 16:29:44 stderr conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/psycopg2/init.py", line 127, in connect
2021-02-22 16:29:44 stderr connection = Database.connect(**conn_params)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/postgresql/base.py", line 187, in get_new_connection
2021-02-22 16:29:44 stderr return func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2021-02-22 16:29:44 stderr self.connection = self.get_new_connection(conn_params)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 200, in connect
2021-02-22 16:29:44 stderr return func(*args, **kwargs)
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/utils/asyncio.py", line 26, in inner
2021-02-22 16:29:44 stderr self.connect()
2021-02-22 16:29:44 stderr File "/opt/recipes/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
2021-02-22 16:29:44 stderr Traceback (most recent call last):
2021-02-22 16:27:32 stdout Updating database

nginx:

date stream content
2021-02-22 16:33:10 stdout 192.168.96.1 - - [22/Feb/2021:16:33:10 +0000] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" "-"
2021-02-22 16:31:35 stdout 192.168.96.1 - - [22/Feb/2021:16:31:35 +0000] "GET / HTTP/1.1" 504 167 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" "-"
2021-02-22 16:31:35 stderr 2021/02/22 16:31:35 [error] 22#22: *8 upstream timed out (110: Operation timed out) while connecting to upstream, client: 192.168.96.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://192.168.96.3:8080/", host: "192.168.1.99:8001"
2021-02-22 16:30:34 stdout 192.168.96.1 - - [22/Feb/2021:16:30:34 +0000] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" "-"
2021-02-22 16:29:15 stdout 192.168.96.1 - - [22/Feb/2021:16:29:15 +0000] "GET /favicon.ico HTTP/1.1" 499 0 "http://192.168.1.99:8001/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" "-"
2021-02-22 16:29:15 stdout 192.168.96.1 - - [22/Feb/2021:16:29:15 +0000] "GET / HTTP/1.1" 504 167 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" "-"
2021-02-22 16:29:15 stderr 2021/02/22 16:29:15 [error] 23#23: *3 upstream timed out (110: Operation timed out) while connecting to upstream, client: 192.168.96.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://192.168.96.3:8080/", host: "192.168.1.99:8001"
2021-02-22 16:28:15 stdout 192.168.96.1 - - [22/Feb/2021:16:28:15 +0000] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0" "-"
2021-02-22 16:27:36 stdout /docker-entrypoint.sh: Configuration complete; ready for start up
2021-02-22 16:27:36 stdout /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
2021-02-22 16:27:36 stdout /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
2021-02-22 16:27:36 stdout 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not exist
2021-02-22 16:27:36 stdout /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
2021-02-22 16:27:36 stdout /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
2021-02-22 16:27:36 stdout /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
puckzuck commented 3 years ago

Ok. Wow. Because the Containers on the Synology NAS kept running and did not crash, I just thought I'd give it a shot to disable the integrated Synology Firewall. And guess what: Now all is good. It still is weird tho - the firewall is set up to allow ALL connections from my inside my LAN. Even now, if I create a rule to allow connections to port 8001 from ALL IPs, it does not work.

Thank you so much for your help! I am so sorry for all the time you put in to help me out here. shame

vabene1111 commented 3 years ago

No worries, glad you got it working :) if you need anything else feel free to ask

Nailik commented 2 years ago

Did you manage to fix your issue without completely disabling the Firewall? It worked for quite a while on my Synology Nas but stopped working on DSM 6 and recently i upgraded to DSM7 but still can't get it running, i also get a 504 error. I think nginx doesnt not work anymore and we should use the build in reverse proxy feature but i'm not sure how to set it up correctly.

Nailik commented 2 years ago

I actually found the issue: You need to add an outgoing rule to the firewall.

Security -> Firewall -> Edit -> Create -> Ports:All Source-IP : Specific IP : Select Subnet -> Ip-Adress: 127.18.0.0 (or whatever your docker containers subnet has as ip) Ip-Area: 255.255.255.0

OK->OK->Ok And then your docker container can actually talk to you ;)

I will soon create a pull request for new documentation

Nailik commented 2 years ago

created a pull request https://github.com/TandoorRecipes/recipes/issues/1090