Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx Homepage after installation with Docker-Compose behind traefik #3154

Open
Cloufish opened this issue May 7, 2024 · 5 comments
Open
Labels
setup issue possibly or definitely an issue with the user setup

Comments

@Cloufish
Copy link

Cloufish commented May 7, 2024

Issue

I get following homepage after setting up Tandoor with Docker Swarm behind Traefik:

image

The changes that I added were server.port in traefik labels
Without It I got "Bad Gateway" error when accessing the page.

Tandoor Version

latest

OS Version

Ubuntu 23.04 x86_64

Setup

Docker / Docker-Compose

Reverse Proxy

Traefik

Other

Docker Swarm

Environment file

My .env (default one):

# ---------------------------------------------------------------------------
# This template contains only required options.
# Visit the docs to find more https://docs.tandoor.dev/system/configuration/
# ---------------------------------------------------------------------------

# random secret key, use for example `base64 /dev/urandom | head -c50` to generate one
SECRET_KEY=h8wPtAT+2pLRQFPBeHIgqwLF2HywSfTiEJ5QZkPgdmBFTVTvv7% # I will change it

# 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_DB=djangodb
POSTGRES_PORT=5432
POSTGRES_USER=djangouser
POSTGRES_PASSWORD=test

Docker-Compose file

My docker-compose:

version: "3.5"
services:
  tandoor_db:
    restart: always
    image: postgres:16-alpine
    ports:
      - "80"
    volumes:
      - /home/swarm/tandoor/postgresql:/var/lib/postgresql/data
    env_file:
      - /home/swarm/tandoor/.env
    networks:
      - tandoor

  web_recipes:
    restart: always
    image: vabene1111/recipes
    env_file:
      - /home/swarm/tandoor/.env
    volumes:
      - tandoor-volume:/opt/recipes/staticfiles
      - nginx_config:/opt/recipes/nginx/conf.d
      - /home/swarm/tandoor/mediafiles:/opt/recipes/mediafiles
    depends_on:
      - tandoor_db
    networks:
      - tandoor

  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    networks:
      - web
      - tandoor
    env_file:
      - /home/swarm/tandoor/.env
    volumes:
      # Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
      - nginx_config:/etc/nginx/conf.d:ro
      - tandoor-volume:/static:ro
      - /home/swarm/tandoor/mediafiles:/media:ro
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.tandoor.rule=Host(`tandoor.home`)"
        - "traefik.http.services.tandoor.loadbalancer.server.port=80" # I added this because the service would not resolve. Without it I had "Bad Gateway"
        - "traefik.docker.network=web"
        - "io.portainer.accesscontrol.users=admin"
        - "traefik.http.routers.tandoor.tls=true"
    depends_on:
      - web_recipes

networks:
  tandoor:
    driver: overlay
    attachable: true
    name: tandoor
  web:
    external: true
    name: web

volumes:
  nginx_config:
  tandoor-volume:

Relevant logs

nginx logs:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/05/07 15:13:02 [notice] 1#1: using the "epoll" event method
2024/05/07 15:13:02 [notice] 1#1: nginx/1.25.5
2024/05/07 15:13:02 [notice] 1#1: built by gcc 13.2.1 20231014 (Alpine 13.2.1_git20231014) 
2024/05/07 15:13:02 [notice] 1#1: OS: Linux 6.2.0-26-generic
2024/05/07 15:13:02 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/05/07 15:13:02 [notice] 1#1: start worker processes
2024/05/07 15:13:02 [notice] 1#1: start worker process 21
2024/05/07 15:13:02 [notice] 1#1: start worker process 22
2024/05/07 15:13:02 [notice] 1#1: start worker process 23
2024/05/07 15:13:02 [notice] 1#1: start worker process 24
2024/05/07 15:13:02 [notice] 1#1: start worker process 25
10.0.1.59 - - [07/May/2024:15:18:31 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
10.0.1.59 - - [07/May/2024:15:19:35 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
10.0.1.200 - - [07/May/2024:15:36:53 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
2024/05/07 15:37:18 [error] 22#22: *2 "/usr/share/nginx/html/search/index.html" is not found (2: No such file or directory), client: 10.0.1.200, server: localhost, request: "GET //search/ HTTP/1.1", host: "tandoor.home"
10.0.1.200 - - [07/May/2024:15:37:18 +0000] "GET //search/ HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
2024/05/07 15:37:22 [error] 22#22: *2 "/usr/share/nginx/html/search/index.html" is not found (2: No such file or directory), client: 10.0.1.200, server: localhost, request: "GET /search/ HTTP/1.1", host: "tandoor.home"
10.0.1.200 - - [07/May/2024:15:37:22 +0000] "GET /search/ HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
2024/05/07 15:44:34 [error] 23#23: *3 "/usr/share/nginx/html/search/index.html" is not found (2: No such file or directory), client: 10.0.1.200, server: localhost, request: "GET /search/ HTTP/1.1", host: "tandoor.home"
10.0.1.200 - - [07/May/2024:15:44:34 +0000] "GET /search/ HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
2024/05/07 15:45:02 [error] 23#23: *3 "/usr/share/nginx/html/search/index.html" is not found (2: No such file or directory), client: 10.0.1.200, server: localhost, request: "GET /search/ HTTP/1.1", host: "tandoor.home"
10.0.1.200 - - [07/May/2024:15:45:02 +0000] "GET /search/ HTTP/1.1" 404 555 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"

tandoor_db logs:

PostgreSQL Database directory appears to contain a database; Skipping initialization
2024-05-07 12:41:15.515 UTC [1] LOG:  starting PostgreSQL 16.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 13.2.1_git20231014) 13.2.1 20231014, 64-bit
2024-05-07 12:41:15.515 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2024-05-07 12:41:15.516 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2024-05-07 12:41:15.520 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2024-05-07 12:41:15.526 UTC [24] LOG:  database system was shut down at 2024-05-07 12:40:56 UTC
2024-05-07 12:41:15.532 UTC [1] LOG:  database system is ready to accept connections
2024-05-07 12:46:15.625 UTC [22] LOG:  checkpoint starting: time
2024-05-07 12:46:15.642 UTC [22] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.004 s, sync=0.002 s, total=0.017 s; sync files=2, longest=0.002 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/195D490, redo lsn=0/195D458

web_recipes logs (If It listens to port 8080, then why do we need nginx_recipes container?):

  Applying cookbook.0146_alter_userpreference_use_fractions... OK
  Applying cookbook.0147_keyword_to_tree... OK
  Applying cookbook.0148_auto_20210813_1829... OK
  Applying cookbook.0149_fix_leading_trailing_spaces... OK
  Applying cookbook.0150_food_to_tree... OK
  Applying cookbook.0151_auto_20210915_1037... OK
  Applying cookbook.0152_automation... OK
  Applying cookbook.0153_auto_20210915_2327... OK
  Applying cookbook.0154_auto_20210922_1705... OK
  Applying cookbook.0155_mealtype_default... OK
  Applying cookbook.0156_searchpreference_trigram_threshold... OK
  Applying cookbook.0157_alter_searchpreference_trigram... OK
  Applying cookbook.0158_userpreference_use_kj... OK
  Applying cookbook.0159_add_shoppinglistentry_fields... OK
  Applying cookbook.0160_delete_shoppinglist_orphans... OK
  Applying cookbook.0161_alter_shoppinglistentry_food... OK
  Applying cookbook.0162_userpreference_csv_delim... OK
  Applying cookbook.0163_auto_20220105_0758... OK
  Applying cookbook.0164_space_show_facet_count... OK
  Applying cookbook.0165_remove_step_type... OK
  Applying cookbook.0166_alter_userpreference_shopping_add_onhand... OK
  Applying cookbook.0167_userpreference_left_handed... OK
  Applying cookbook.0168_add_unit_searchfields... OK
  Applying cookbook.0169_exportlog... OK
  Applying cookbook.0170_auto_20220207_1848... OK
  Applying cookbook.0171_alter_searchpreference_trigram_threshold... OK
  Applying cookbook.0172_ingredient_original_text... OK
  Applying cookbook.0173_recipe_source_url... OK
  Applying cookbook.0174_alter_food_substitute_userspace... OK
  Applying cookbook.0175_remove_userpreference_space... OK
  Applying cookbook.0176_alter_searchpreference_icontains_and_more... OK
  Applying cookbook.0177_recipe_show_ingredient_overview... OK
  Applying cookbook.0178_remove_userpreference_search_style_and_more... OK
  Applying cookbook.0179_recipe_private_recipe_shared... OK
  Applying cookbook.0180_invitelink_reusable... OK
  Applying cookbook.0181_space_image... OK
  Applying cookbook.0182_userpreference_image... OK
  Applying cookbook.0183_alter_space_image... OK
  Applying cookbook.0184_alter_userpreference_image... OK
  Applying cookbook.0185_food_plural_name_ingredient_always_use_plural_food_and_more... OK
  Applying cookbook.0186_automation_order_alter_automation_type... OK
  Applying cookbook.0187_alter_space_use_plural... OK
  Applying cookbook.0188_space_no_sharing_limit... OK
  Applying cookbook.0189_property_propertytype_unitconversion_food_fdc_id_and_more... OK
  Applying cookbook.0190_auto_20230525_1506...Transforming nutrition information, this might take a while on large databases
 OK
  Applying cookbook.0191_foodproperty_property_import_food_id_and_more... OK
  Applying cookbook.0192_food_food_unique_open_data_slug_per_space_and_more... OK
  Applying cookbook.0193_space_internal_note... OK
  Applying cookbook.0194_alter_food_properties_food_amount... OK
  Applying cookbook.0195_invitelink_internal_note_userspace_internal_note_and_more... OK
  Applying cookbook.0196_food_url... OK
  Applying cookbook.0197_step_show_ingredients_table_and_more... OK
  Applying cookbook.0198_propertytype_order... OK
  Applying cookbook.0199_alter_propertytype_options_alter_automation_type_and_more... OK
  Applying cookbook.0200_alter_propertytype_options_remove_keyword_icon_and_more... OK
  Applying cookbook.0201_rename_date_mealplan_from_date_mealplan_to_date... OK
  Applying cookbook.0202_remove_space_show_facet_count... OK
  Applying cookbook.0203_alter_unique_contstraints... OK
  Applying cookbook.0204_propertytype_fdc_id... OK
  Applying cookbook.0205_alter_food_fdc_id_alter_propertytype_fdc_id... OK
  Applying cookbook.0206_rename_sticky_navbar_userpreference_nav_sticky_and_more... OK
  Applying cookbook.0207_space_logo_color_128_space_logo_color_144_and_more... OK
  Applying cookbook.0208_space_app_name_userpreference_max_owned_spaces... OK
  Applying cookbook.0209_remove_space_use_plural... OK
  Applying cookbook.0210_shoppinglistentry_updated_at... OK
  Applying cookbook.0211_recipebook_order... OK
  Applying cookbook.0212_alter_property_property_amount... OK
  Applying cookbook.0213_remove_property_property_unique_import_food_per_space_and_more... OK
  Applying cookbook.0214_cooklog_comment_cooklog_updated_at_and_more... OK
  Applying cookbook.0215_connectorconfig... OK
  Applying cookbook.0216_delete_shoppinglist... OK
  Applying cookbook.0217_alter_userpreference_default_page... OK
  Applying oauth2_provider.0001_initial... OK
  Applying oauth2_provider.0002_auto_20190406_1805... OK
  Applying oauth2_provider.0003_auto_20201211_1314... OK
  Applying oauth2_provider.0004_auto_20200902_2022... OK
  Applying oauth2_provider.0005_auto_20211222_2352... OK
  Applying oauth2_provider.0006_alter_application_client_secret... OK
  Applying oauth2_provider.0007_application_post_logout_redirect_uris... OK
  Applying sessions.0001_initial... OK
  Applying sites.0001_initial... OK
  Applying sites.0002_alter_domain_unique... OK
  Applying socialaccount.0001_initial... OK
  Applying socialaccount.0002_token_max_lengths... OK
  Applying socialaccount.0003_extra_data_default_dict... OK
  Applying socialaccount.0004_app_provider_id_settings... OK
  Applying socialaccount.0005_socialtoken_nullable_app... OK
  Applying socialaccount.0006_alter_socialaccount_extra_data... OK
Generating static files
js-reverse file written to /opt/recipes/cookbook/static/django_js_reverse
575 static files copied to '/opt/recipes/staticfiles', 1491 post-processed.
Done
[2024-05-07 17:46:59 +0000] [1] [INFO] Starting gunicorn 21.2.0
[2024-05-07 17:46:59 +0000] [1] [INFO] Listening at: http://[::]:8080 (1)
[2024-05-07 17:46:59 +0000] [1] [INFO] Using worker: gthread
[2024-05-07 17:46:59 +0000] [16] [INFO] Booting worker with pid: 16
[2024-05-07 17:46:59 +0000] [17] [INFO] Booting worker with pid: 17
[2024-05-07 17:46:59 +0000] [18] [INFO] Booting worker with pid: 18
@Cloufish Cloufish added the setup issue possibly or definitely an issue with the user setup label May 7, 2024
@Cloufish Cloufish changed the title Nginx Homepage after installation Nginx Homepage after installation with Docker-Compose behind traefik May 7, 2024
@Cloufish
Copy link
Author

Cloufish commented May 7, 2024

I moved the traefik labels to web_recipes container and changed "traefik.http.services.tandoor.loadbalancer.server.port=80" to port 8080

The website works and looks great
Why do we need nginx_recipes container?

image

@smilerz
Copy link
Collaborator

smilerz commented May 7, 2024

The website works and looks great Why do we need nginx_recipes container?

https://docs.tandoor.dev/install/docker/#nginx-vs-gunicorn

@smilerz smilerz closed this as completed May 7, 2024
@Cloufish
Copy link
Author

Cloufish commented May 7, 2024

The website works and looks great Why do we need nginx_recipes container?

https://docs.tandoor.dev/install/docker/#nginx-vs-gunicorn

Okay but wait @smilerz !!!
You've convinced me...

But why the nginx container doesn't forward the requests to the web_recipes that listens on 8080?

@smilerz
Copy link
Collaborator

smilerz commented May 7, 2024

nginx does forward to tandoor port 8080. there is an example traefik config here.

@Cloufish
Copy link
Author

Cloufish commented May 7, 2024

I've modified the docker-compose according to what you posted @smilerz
Now it's:

version: "3.5"
services:
  tandoor_db:
    restart: always
    image: postgres:16-alpine
    ports:
      - "80"
    volumes:
      - /home/swarm/tandoor/postgresql:/var/lib/postgresql/data
    env_file:
      - /home/swarm/tandoor/.env
    networks:
      - tandoor

  web_recipes:
    restart: always
    image: vabene1111/recipes
    env_file:
      - /home/swarm/tandoor/.env
    volumes:
      - tandoor-volume:/opt/recipes/staticfiles
      - nginx_config:/opt/recipes/nginx/conf.d
      - /home/swarm/tandoor/mediafiles:/opt/recipes/mediafiles
    depends_on:
      - tandoor_db
    networks:
      - web
      - tandoor
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.recipes.rule=Host(`tandoor.home`) && PathPrefix(`/*`)"
        - "traefik.http.services.recipes.loadbalancer.server.port=8080"
        - "traefik.docker.network=recipes"
        - "io.portainer.accesscontrol.users=admin"
        - "traefik.http.routers.recipes.tls=true"
  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    ports:
      - "80"
    networks:
      - web
      - tandoor
    env_file:
      - /home/swarm/tandoor/.env
    volumes:
      # Do not make this a bind mount, see https://docs.tandoor.dev/install/docker/#volumes-vs-bind-mounts
      - nginx_config:/etc/nginx/conf.d:ro
      - tandoor-volume:/static:ro
      - /home/swarm/tandoor/mediafiles:/media:ro
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.tandoor.rule=Host(`tandoor.home`)"
        - "traefik.http.services.tandoor.loadbalancer.server.port=80"
        - "traefik.docker.network=web"
        - "io.portainer.accesscontrol.users=admin"
        - "traefik.http.routers.tandoor.tls=true"
    depends_on:
      - web_recipes

networks:
  tandoor:
    driver: overlay
    attachable: true
    name: tandoor
  web:
    external: true
    name: web

volumes:
  nginx_config:
  tandoor-volume:

But the nginx still does not forward the request. I have the 404 error though
From nginx_recipes:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: can not modify /etc/nginx/conf.d/default.conf (read-only file system?)
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/05/07 19:30:25 [notice] 1#1: using the "epoll" event method
2024/05/07 19:30:25 [notice] 1#1: nginx/1.25.5
2024/05/07 19:30:25 [notice] 1#1: built by gcc 13.2.1 20231014 (Alpine 13.2.1_git20231014) 
2024/05/07 19:30:25 [notice] 1#1: OS: Linux 6.2.0-26-generic
2024/05/07 19:30:25 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/05/07 19:30:25 [notice] 1#1: start worker processes
2024/05/07 19:30:25 [notice] 1#1: start worker process 20
2024/05/07 19:30:25 [notice] 1#1: start worker process 21
2024/05/07 19:30:25 [notice] 1#1: start worker process 22
2024/05/07 19:30:25 [notice] 1#1: start worker process 23
2024/05/07 19:30:25 [notice] 1#1: start worker process 24
10.0.1.35 - - [07/May/2024:19:30:50 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/8.5.0" "10.0.0.2"
10.0.1.35 - - [07/May/2024:19:41:14 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
2024/05/07 19:41:16 [error] 21#21: *2 open() "/usr/share/nginx/html/service-worker.js" failed (2: No such file or directory), client: 10.0.1.35, server: localhost, request: "GET /service-worker.js HTTP/1.1", host: "tandoor.home", referrer: "https://tandoor.home/service-worker.js"
10.0.1.35 - - [07/May/2024:19:41:16 +0000] "GET /service-worker.js HTTP/1.1" 404 555 "https://tandoor.home/service-worker.js" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" "10.0.0.2"
2024/05/07 19:43:29 [error] 22#22: *3 open() "/usr/share/nginx/html/service-worker.js" failed (2: No such file or directory), client: 10.0.1.35, server: localhost, request: "GET /service-worker.js HTTP/1.1", host: "tandoor.home"
10.0.1.35 - - [07/May/2024:19:43:29 +0000] "GET /service-worker.js HTTP/1.1" 404 153 "-" "curl/8.5.0" "10.0.0.2"

So it doesn't forward in my case

I tried using curl:

/ # curl https://tandoor.home/service-worker.js
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.25.5</center>
</body>
</html>

I really need explanation to this... :/
Also could you open this issue?

@smilerz smilerz reopened this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
setup issue possibly or definitely an issue with the user setup
Projects
None yet
Development

No branches or pull requests

2 participants