monicahq / monica

Personal CRM. Remember everything about your friends, family and business relationships.
https://beta.monicahq.com
GNU Affero General Public License v3.0
21.04k stars 2.09k forks source link

Unable to access monicahq un subpath via reverse proxy #7309

Open gardiol opened 1 month ago

gardiol commented 1 month ago

⚠️ This issue respects the following points: ⚠️

Bug description

Unable to access monicahq from reverse proxy on subpath (mydomain.com/monicahq)

Steps to reproduce

I have deployed mponicahq using docker compose, here is the compose file i am using:

version: "3.9"

services:
  app:
    image: monica:apache
    depends_on:
      - db
    ports:
      - 9980:80
    environment:
      - APP_ENV=local
      - APP_KEY=blahblahblah
      - APP_URL=https://mydomain.com/monicahq
      - APP_TRUSTED_PROXIES=*
      - DB_HOST=db
      - DB_DATABASE=monica
      - DB_USERNAME=monica
      - DB_PASSWORD=monica_secret
      - LOG_CHANNEL=stderr
      - CACHE_DRIVER=database
      - SESSION_DRIVER=database
      - QUEUE_DRIVER=sync
    volumes:
      - /monicahq/storage:/var/www/html/storage
    networks:
      - monicahq-net

  db:
    image: mariadb:latest
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=true
      - MYSQL_DATABASE=monica
      - MYSQL_USER=monica
      - MYSQL_PASSWORD=monica_secret
    volumes:
      - /monicahq/mysql:/var/lib/mysql
    networks:
      - monicahq-net

networks:
  monicahq-net: {}

It runs, and i can access the register page via http://127.0.0.1:9980

If i add on top of it my reverse proxy:

location /monicahq/ {
    proxy_pass         http://127.0.0.1:9980/;
    proxy_redirect     off;
    proxy_set_header   Host $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-Host $server_name;
}

(only relevant location section)

it doesnt work. Browser report a 302 redirect to http://mydomain.com/register insterad of the correct https://mydomain.com/monicahq/register that i am expecting.

Am i doing something wrong? According to the docs i could find, it should work.

Expected behavior

Monicahq accessible at https://mydomain.com/monicahq

Environment

Your own self-hosted instance (monica v4)

Version of Monica

No response

Installation method

Docker image

Web server

Apache

Database engine version

MariaDB

Additional info

No response