TandoorRecipes / recipes

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

Images not loaded after server restart (404), MEDIA_URL fix doesn't seem to work #2516

Closed DammersH closed 1 year ago

DammersH commented 1 year ago

Issue

Hello folks,

I'm a little bit lost here, were I made a wrong turn.

What i did tried after reading the FAQ was adding one of these entries to the .env - MEDIA_URL=https://<myserver.name>9999/media/ - MEDIA_URL=https://<myserver.name>9999/media/recipes - MEDIA_URL=https://<myserver.ipadress>9999/media/ - MEDIA_URL=https://<myserver.ipadress>9999/media/recipes

Out of fear I reuploaded all the pictures just to be sure, that I didn't deleted them

Tandoor Version

1.5.2

OS Version

QNAP QTS 5.0.1

Setup

Docker / Docker-Compose

Reverse Proxy

No reverse proxy

Other

No response

Environment file

- DEBUG=0
      - SQL_DEBUG=0
      - ALLOWED_HOSTS=*
      - SECRET_KEY=secretkey
      - TIMEZONE=Europe/Berlin
      - DB_ENGINE=django.db.backends.postgresql
      - POSTGRES_HOST=db_recipes
      - POSTGRES_PORT=5432
      - POSTGRES_USER=djangouser
      - POSTGRES_PASSWORD=superawesomesecretkeydeluxetothemax
      - POSTGRES_DB=djangodb
      - FRACTION_PREF_DEFAULT=0
      - COMMENT_PREF_DEFAULT=1
      - SHOPPING_MIN_AUTOSYNC_INTERVAL=5
      - GUNICORN_MEDIA=0
      - REVERSE_PROXY_AUTH=0
      - ENABLE_PDF_EXPORT=1

Docker-Compose file

`version: "3"
services:
  db_recipes:
    restart: always
    image: postgres:11-alpine
    volumes:
      - /share/Container/postgresdb:/var/lib/postgresql/data
    environment:
      - SQL_DEBUG=0
      - POSTGRES_HOST=db_recipes
      - POSTGRES_PORT=5432
      - POSTGRES_USER=djangouser
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=djangodb   
  web_recipes:
    image: vabene1111/recipes
    restart: always
    environment:
      - DEBUG=0
      - SQL_DEBUG=0
      - ALLOWED_HOSTS=*
      - SECRET_KEY=secretkey
      - TIMEZONE=Europe/Berlin
      - DB_ENGINE=django.db.backends.postgresql
      - POSTGRES_HOST=db_recipes
      - POSTGRES_PORT=5432
      - POSTGRES_USER=djangouser
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=djangodb
      - FRACTION_PREF_DEFAULT=0
      - COMMENT_PREF_DEFAULT=1
      - SHOPPING_MIN_AUTOSYNC_INTERVAL=5
      - GUNICORN_MEDIA=0
      - REVERSE_PROXY_AUTH=0
      - ENABLE_PDF_EXPORT=1
    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:
      - 9999:80
    environment:
      - DEBUG=0
      - SQL_DEBUG=0
      - ALLOWED_HOSTS=*
      - SECRET_KEY=secretkey
      - TIMEZONE=Europe/Berlin
      - DB_ENGINE=django.db.backends.postgresql
      - POSTGRES_HOST=db_recipes
      - POSTGRES_PORT=5432
      - POSTGRES_USER=djangouser
      - POSTGRES_PASSWORD=superawesomesecretkeydeluxetothemax
      - POSTGRES_DB=djangodb
      - FRACTION_PREF_DEFAULT=0
      - COMMENT_PREF_DEFAULT=1
      - SHOPPING_MIN_AUTOSYNC_INTERVAL=5
      - GUNICORN_MEDIA=0
      - REVERSE_PROXY_AUTH=0
      - ENABLE_PDF_EXPORT=1
    depends_on:
      - web_recipes
    volumes:
      - nginx_config:/etc/nginx/conf.d:ro
      - staticfiles:/static:ro
      - ./mediafiles:/media:ro
volumes:
  nginx_config:
  staticfiles:`

Relevant logs

What I found looking through the system was this gunicorn error(?)

wsgi.errors:<gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7f24920d1c00>
wsgi.version:(1, 0)
wsgi.multithread:True
wsgi.multiprocess:True
wsgi.run_once:False
wsgi.file_wrapper:
wsgi.input_terminated:True
wsgi.input:<gunicorn.http.body.Body object at 0x7f2491a2f100>
wsgi.url_scheme:http
gloriousDan commented 1 year ago

First of all, did you turn the debug mode on by using DEBUG=1? Afterwards there should be additional log output which helps with debugging the issue.

From a first look your setup seems fine. Since you mounted the mediafiles folder via a bind mount, the photos should be in the local mediafiles folder. Can you check its contents and make sure that all the images are indeed there?

I'm not sure about the gunicorn error, but it shouldn't have anything to do with loading the images since they should be served directly by nginx instead of gunicorn.

DammersH commented 1 year ago

Okay, interesseting the folder for the mediafiles was empty. Not that I did this on puropose, since I can only access it via shell. I will try readding the pictures and look what happens.

Where shall I look for the log files? Docker log or tandoor itself? Tandorr recognizes the debug mode, but I don't see any relevant logs when adding pictures.

'Current' logfile looks like this: `Gunicorn Media: False Sqlite: False Debug: True

SERVER_PROTOCOL:HTTP/1.0 REMOTE_ADDR:172.29.8.4 SERVER_PORT:8080

HTTP_HOST:mooncake:9999 HTTP_CONNECTION:close HTTP_USER_AGENT:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0 HTTP_ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8 HTTP_ACCEPT_LANGUAGE:de,en-US;q=0.7,en;q=0.3 HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_REFERER:http://:9999/view/recipe/23 HTTP_DNT:1 HTTP_COOKIE:remeber=1; csrftoken=QBh06LKV8uvvElISE18NPlqgT4A6oifA; sessionid=zslrxakf82v5ogonr70jr3bh5i6g0hwk; Squeezebox-expandPlayerControl=false; Squeezebox-expanded-MY_MUSIC=1; Squeezebox-expanded-FAVORITES=1; Squeezebox-expanded-PLUGINS=1; Squeezebox-expanded-PLUGIN_MY_APPS_MODULE_NAME=1; Squeezebox-expanded-RADIO=1; Squeezebox-player=00%3A04%3A20%3A26%3A13%3Af2; Squeezebox-enableHiDPI=1.5; Squeezebox-playersettings=null; Squeezebox-advancedsettings=plugins/SuperDateTime/settings/basic.html%3F; Squeezebox-expanded-updatePlugins=1; Squeezebox-expanded-activePlugins=1; Squeezebox-expanded-inactivePlugins=1; Squeezebox-expanded-otherPlugins0=1; Squeezebox-albumView=; CSRF-Token-72MFM=DF9DL9XydGrr5GbmihxnGgjTJv99MF6Z; search_settings3=%7B%22advanced_search_visible%22%3Afalse%2C%22explain_visible%22%3Afalse%2C%22search_input%22%3A%22%22%2C%22search_internal%22%3Afalse%2C%22search_keywords%22%3A%5B%7B%22items%22%3A%5B%5D%2C%22operator%22%3Atrue%2C%22not%22%3Afalse%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Afalse%2C%22not%22%3Afalse%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Atrue%2C%22not%22%3Atrue%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Afalse%2C%22not%22%3Atrue%7D%5D%2C%22search_foods%22%3A%5B%7B%22items%22%3A%5B%5D%2C%22operator%22%3Atrue%2C%22not%22%3Afalse%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Afalse%2C%22not%22%3Afalse%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Atrue%2C%22not%22%3Atrue%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Afalse%2C%22not%22%3Atrue%7D%5D%2C%22search_books%22%3A%5B%7B%22items%22%3A%5B%5D%2C%22operator%22%3Atrue%2C%22not%22%3Afalse%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Afalse%2C%22not%22%3Afalse%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Atrue%2C%22not%22%3Atrue%7D%2C%7B%22items%22%3A%5B%5D%2C%22operator%22%3Afalse%2C%22not%22%3Atrue%7D%5D%2C%22search_units%22%3A%5B%5D%2C%22search_units_or%22%3Atrue%2C%22search_rating_gte%22%3Atrue%2C%22timescooked_gte%22%3Atrue%2C%22makenow%22%3Afalse%2C%22cookedon_gte%22%3Atrue%2C%22createdon_gte%22%3Atrue%2C%22updatedon_gte%22%3Atrue%2C%22viewedon_gte%22%3Atrue%2C%22sort_order%22%3A%5B%7B%22id%22%3A3%2C%22text%22%3A%22Name%20(A-z)%22%2C%22value%22%3A%22name%22%7D%5D%2C%22pagination_page%22%3A1%2C%22keywords_fields%22%3A1%2C%22foods_fields%22%3A1%2C%22books_fields%22%3A1%2C%22rating_fields%22%3A1%2C%22units_fields%22%3A1%7D HTTP_UPGRADE_INSECURE_REQUESTS:1 HTTP_SEC_GPC:1

wsgi.errors:<gunicorn.http.wsgi.WSGIErrorsWrapper object at 0x7fe54e847100> wsgi.version:(1, 0) wsgi.multithread:True wsgi.multiprocess:True wsgi.run_once:False wsgi.file_wrapper: wsgi.input_terminated:True wsgi.input:<gunicorn.http.body.Body object at 0x7fe54e6a2da0> wsgi.url_scheme:http `

gloriousDan commented 1 year ago

The logs should be visible in the docker container The output you sent is not the logfile but just some debug parameters.

DammersH commented 1 year ago

The log files don't throw any error.

It seems that shutting down the NAS during the night somehow purges the media folder. Because the media files survive a container reboot but didn't survived the NAS shutdown.

Must be somehow a QNAP behavior...

I will try a different approach for storing the pictures and will come back with more information

DammersH commented 1 year ago

It seems that solved it:

Instead of using a bind mount I went for volume and switched everything from ./mediafiles to mediafiles and created a corresponding volume.

Thanks for the help @gloriousDan and the hint where to look for the media files.