shaarli / Shaarli

The personal, minimalist, super-fast, database free, bookmarking service - community repo
https://shaarli.readthedocs.io/
Other
3.4k stars 287 forks source link

root_url not taken into account for template assets and routing using Caddy #2031

Open locness3 opened 10 months ago

locness3 commented 10 months ago

I'm trying to set up Shaarli under a subdirectory of my server (without the installation directory being a subdirectory of my server's root content directory).

Previously I used nginx and PHP 7.4, and Shaarli was able to auto-detect that it ran in a subdirectory, and used the proper path for routing and assets, so the site was usable.

Now I'm trying with Caddy and PHP 8.2. Shaarli does not automatically detect the subdirectory so I set general.root_url and general.header_link in Shaarli's config.json.php to the full address of the subdirectory : http://locness.local/grub/ (same results with and without escaping the slashes)

Visiting http://locness.local/grub/ or any URL under that shows a 404 page instead of the correct Shaarli page, probably meaning that the routing ignores the root_url. No CSS nor JS is loaded.

Looking at the page source it turns out those are linked from the webroot :

<link type="text/css" rel="stylesheet" href="/tpl/default/css/shaarli.min.css?v=9f4e2359e31f51e95970e3c8899049eb8f4552822027e20b3429aee78b8b4feb" />

...

<script src="/tpl/default/js/shaarli.min.js?v=9f4e2359e31f51e95970e3c8899049eb8f4552822027e20b3429aee78b8b4feb"></script>

There is only one instance of the root_url being used : the feeds

<link rel="alternate" type="application/atom+xml" href="http://locness.local/grub/feed/atom?" title="ATOM Feed" />
<link rel="alternate" type="application/rss+xml" href="http://locness.local/grub/feed/rss?" title="RSS Feed" />
my Caddyfile ``` http://locness.local { log encode gzip # Set this path to your site's directory. root * /usr/share/caddy # Enable the static file server. file_server handle_path /grub/* { root * /var/www/shaarli_grub php_fastcgi * unix//run/php/php8.2-fpm.sock } } ```
my truncated shaarli config.json.php ``` ```

Let me know if you need any other config.

nodiscc commented 10 months ago

Hi, could it be a server-side caching problem? Can you delete the contents of tmp/, restart php8.2-fpm, and try again? Does it fix the problem?

locness3 commented 10 months ago

Hi, could it be a server-side caching problem? Can you delete the contents of tmp/, restart php8.2-fpm, and try again? Does it fix the problem?

I've did it to no avail, I've even rebooted the system a few times but nothing.

nodiscc commented 10 months ago

Sorry I am not familiar with Caddy, a new section could be added to https://shaarli.readthedocs.io/en/master/Reverse-proxy.html if someone wants to provide a working Caddy configuration.

At first glance I'm not sure handle_path would be the correct directive here, since it strips the prefix. Have you tried with handle or other directives?

nodiscc commented 6 months ago

Hi @locness3 any news regarding the problem when using Caddy? Were you able to fix it?

EwenKorr commented 5 months ago

I'm having the same issue, but with Docker and Traefik v2. I'm willing to use Shaarli in a subdirectory. Here's the relevant configuration:

config.json.php:

[…]
    "general": {
        "root_url": "https:\/\/subdomain.domain.tld\/liens\/",
        "header_link": "\/liens\/",                       
        "links_per_page": 20,
        "enabled_plugins": [
            "qrcode",
            "default_colors",
            "shaarli2mastodon"
        ],
        "default_note_title": "Note: ",
        "retrieve_description": true,
        "timezone": "Europe\/Paris",
        "title": "Liammoù Ewen",
        "download_max_size": 4194304,
        "download_timeout": 30,
        "enable_async_metadata": true,
        "tags_separator": " "
    },
[…]

docker-compose.yml:

version: '3'

services:
  shaarli:
    image: shaarli/shaarli:v0.13.0
    restart: unless-stopped
    networks:
      - my_network
    volumes:
      - './cache:/var/www/shaarli/cache'
      - './data:/var/www/shaarli/data'
      - './plugins:/var/www/shaarli/plugins'
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.shaarli.rule=Host(`subdomain.domain.tld`) && PathPrefix(`/liens`)"
      - "traefik.http.routers.shaarli.entrypoints=web"
      - "traefik.http.routers.shaarlitls.rule=Host(`subdomain.domain.tld`) && PathPrefix(`/liens`)"
      - "traefik.http.routers.shaarlitls.entrypoints=websecure"
      - "traefik.http.routers.shaarlitls.tls=true"
      - "traefik.http.routers.shaarlitls.tls.certresolver=letsencrypttls"
      - "traefik.http.routers.shaarlitls.tls.domains[0].main=subdomain.domain.tld"
      - "traefik.docker.network=my_network"

networks:
  my_network:
    external: true

As for @locness3, only the feed URLs contain the subdirectory I've set in root_url.

EwenKorr commented 5 months ago

Nevermind, this seems to be a normal behaviour: https://github.com/shaarli/Shaarli/issues/1244#issuecomment-443507059

I customized the Docker image to have a subdirectory. See also https://github.com/shaarli/Shaarli/issues/1778.