seanmorley15 / AdventureLog

Self-hostable travel tracker and trip planner.
https://adventurelog.app
Other
396 stars 12 forks source link

Images not showing with proxied url #289

Open TheBig-O opened 1 week ago

TheBig-O commented 1 week ago

This has been kicking my butt for two days. I have tried multiple configurations and nothing seems to work. I can access Adventure Log from the public url and I can log in just fine. There are no images though. Each adventure image is a missing image box and is listed with an address pointing at the local host with an address like: http://127.0.0.1:8000/media/images/image_cWwEzGa.webp.

I have proxied the nginx container with:

server {
    listen 80;
#    server_name 192.168.1.174:8787;
    server_name trek2.domain.com;

    location /media/ {
        alias /app/media/;
    }
}

I have also tried variations of the nginx.conf with no success.

The below is my docker-compose.yml:

version: "3.9"
services:
  web:
    #build: ./frontend/
    image: ghcr.io/seanmorley15/adventurelog-frontend:latest
    container_name: adventurelog_web
    restart: unless-stopped
    environment:
#      - PUBLIC_SERVER_URL=http://server:8000
      - PUBLIC_SERVER_URL=https://trek2.domain.com
#      - ORIGIN=http://192.168.1.174:8080
      - ORIGIN=https://trek.domain.com
      - BODY_SIZE_LIMIT=5242880
    ports:
      - 8080:3000
    depends_on:
      - server
  db:
    image: postgres:latest
    container_name: adventurelog_db    
    restart: unless-stopped
    environment:
      POSTGRES_DB: database
      POSTGRES_USER: adventure
      POSTGRES_PASSWORD: password
    volumes:
      - /docker_data/adventurelog/postgres_data:/var/lib/postgresql/data/

  server:
    #build: ./backend/
    image: ghcr.io/seanmorley15/adventurelog-backend:latest
    container_name: adventurelog_server
    restart: unless-stopped
    environment:
      - PGHOST=db
      - PGDATABASE=database
      - PGUSER=adventure
      - PGPASSWORD=Active_Obligate_Devalue2
      - SECRET_KEY=SuperSecret
      - DJANGO_ADMIN_USERNAME=admin
      - DJANGO_ADMIN_PASSWORD=admin
      - DJANGO_ADMIN_EMAIL=my@email.com
      - PUBLIC_SERVER_URL='https://trek2.domain.com'
      - SRF_TRUSTED_ORIGINS=http://192.168.1.174:8080,http://192.168.1.174:8787,https://trek.domain.com,https://trek2.domain.com
      - DEBUG=True
#      - FRONTEND_URL='http://192.168.1.174:8080'
      - FRONTEND_URL=https://trek.domain.com
      - DISABLE_REGISTRATION=True
    ports:
      - 8787:8000
    depends_on:
      - db
    volumes:
      - /_webdir/media_advlog/:/code/media/

  nginx:
    image: nginx:latest
    container_name: adventurelog_nginx
    restart: unless-stopped
    ports:
      - 8280:80
    volumes:
      - /_webdir/media_advlog:/app/media
      - /docker_data/adventurelog/proxy/nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - server

What am I doing wrong? Why can't I figure out how to show images? Do I need to proxy the NGINX container as well? If so, where would I reference it in the other containers? I don't see anything that specifically points to the address:port.

I have running web server containers and can point the server and web frontend at that, so I don't really need the nginx container, but my real concern is just getting this running with an ability to access it from the internet. I'm leaving on a trip this week and would love to be able to document it with this Adventure Log. Thanks for the help. I love the app and have entered a ton of stuff, but would love to access it from the internet as well.

seanmorley15 commented 1 week ago

So there are a few things that hopefully help:

  1. The backend server container has no PUBLIC_SERVER_URL it just has PUBLIC_URL which is what generates a url for the images, so make sure that your image nginx container is accessible and make this match. I have always just used the default nginx container and proxied it again for web use as something like cdn.adventurelog.app, but I'm sure there are ways to do it in one. This would mean just using the plain nginx config provided in the docs without change.
  2. Just in case check SRF_TRUSTED_ORIGINS and make sure its CSRF_TRUSTED_ORIGINS although its probably not necessary for this issue.
  3. Make sure PUBLIC_SERVER_URL=http://server:8000 is used because the stack is in the same docker network.
  4. New version of AdventureLog use postgis so make sure the DB image is image: postgis/postgis:15-3.3
  5. The FRONTEND_URL in the backend is just used for emails so make sure its the domain of the frontend

I love that you are using AdventureLog and I really hope this helps 🤞!

TheBig-O commented 1 week ago

You! Are! The! Man!

After updating from your instructions, things are working as expect. The only issue I had was the conversion from postrges to postgis. When I added that, I got a few errors in the DB log and it refused to start. I hesitant to ditch the postrgres because I haven't figured out a way to export an SQL file that I can re-import into postgis. If you have any tips here, please let pass them along.

Thanks for the quick response and help in getting this going. I can't believe I hopes the environment variables, but I'm glad I asked! Still loving it!!

seanmorley15 commented 1 week ago

I am super happy to hear its working now! Regarding the postgis migration, it should be automatic after switching the image and updating the container. Here is what I recommend:

  1. Make a backup of the database (just in case!)
  2. Stop the containers
  3. Change the image to postgis in the docker compose file
  4. Run docker compose pull
  5. Then run docker compose up -d to start it all up.

I hope you enjoy your trip!

TheBig-O commented 1 week ago

Well... When I swapped out the image tag fro the postgis, I get an error about compatibility: The data directory was initialized by PostgreSQL version 16, which is not compatible with this version 15.4 (Debian 15.4-1.pgdg110+1). Apparently, it doesn't like that my PostgreSQL is version 16. Is there a simple way to export everything from the current database, delete the container, and reestablish the container with postgis? Everything is working now, but I want to make sure I'm running this in its optimal form. I really am enjoying this app.

seanmorley15 commented 1 week ago

Hmm... I wonder if using this tag based on Postgres 16 will help: postgis/postgis:16-3.4 This seems to be a newer version. If it works let me know so I can update the compose file!

TheBig-O commented 1 week ago

So, new error, but this may be fixable. I just won't get a chance to fix it tonight.

DETAIL:  The database was created using collation version 2.36, but the operating system provides version 2.31.
HINT:  Rebuild all objects in this database that use the default collation and run ALTER DATABASE database REFRESH COLLATION VERSION, or build PostgreSQL with the right library version.

Tomorrow, I'll open up the database and get the hint a shot unless you have any thoughts on other options. (After backing up, of course.)

I will add though, the app is up and running even with this database warning. I can access it just fine through its web address.

TheBig-O commented 1 week ago

Okay, I think I'm back up and running with everything sorted out. I fixed the collation error by opening up the database in a psql command line and running these two commands:

REINDEX DATABASE postgres;

ALTER DATABASE postgres REFRESH COLLATION VERSION;

While I was in there, I vacuumed the database and reindexed it. The site is up and running with no issues. Best part? I got it all done before leaving this weekend! Thanks for your help in getting me going.

If I was going to make any suggestions about changing the docker-compose, I would add something about fixing the collation. It's dead simple on the command line, but may not be obvious to some.

seanmorley15 commented 1 week ago

I'm so glad to hear it's working! I will keep this issue open so I remember to fix the docker compose. I hope you have fun on your trip 😁 Enjoy!

TheBig-O commented 1 week ago

I forgot to add one command that may help people with the command line. So, here's all of the necessary commands for those who want to give it a go.

# If you're using docker, you need to get into the database container so that you can work with psql.
docker exec -u 0 -it adventurelog_db bash

# Initiate a psql database connection (assumes database is named postgres with a user named adventure.)
psql -h localhost -d postgres -U adventure -p 5432

# Reindex the database
REINDEX DATABASE postgres;

# Perform the collation alteration
ALTER DATABASE postgres REFRESH COLLATION VERSION;

# Exit psql
\q

Hope this helps someone!