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

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

Open
moeenio opened this issue Nov 2, 2023 · 6 comments
Open
Labels
feedback needed server support installation and configuration issues

Comments

@moeenio
Copy link

moeenio commented Nov 2, 2023

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
<?php /*{
    "resource": {
        "data_dir": "data",
        "config": "data\/config.php",
        "datastore": "data\/datastore.php",
        "ban_file": "data\/ipbans.php",
        "updates": "data\/updates.txt",
        "log": "data\/log.txt",
        "update_check": "data\/lastupdatecheck.txt",
        "history": "data\/history.php",
        "raintpl_tpl": "tpl\/",
        "theme": "default",
        "raintpl_tmp": "tmp\/",
        "thumbnails_cache": "cache",
        "page_cache": "pagecache"
    },
    "security": {
        ...
    },
    "general": {
        "header_link": "http:\/\/locness.local\/grub\/",
        "links_per_page": 20,
        "enabled_plugins": [
            "qrcode",
            "addlink_toolbar",
            "playvideos",
            "archiveorg"
        ],
        "default_note_title": "Note: ",
        "retrieve_description": false,
        "enable_async_metadata": true,
        "tags_separator": " ",
        "timezone": "Europe\/London",
        "title": "...",
        "root_url": "http:\/\/locness.local\/grub\/"
    },
    "updates": {
        "check_updates": true,
        "check_updates_branch": "latest",
        "check_updates_interval": 86400
    },
    "feed": {
        "rss_permalinks": true,
        "show_atom": true
    },
    "privacy": {
        ...
    },
    "thumbnails": {
        ...
    },
    "translation": {
        "language": "auto",
        "mode": "php",
        "extensions": []
    },
    "plugins": {
        "DEFAULT_COLORS_MAIN": "red",
        "DEFAULT_COLORS_BACKGROUND": "",
        "DEFAULT_COLORS_DARK_MAIN": ""
    },
    "formatter": "markdown",
    "credentials": {
        ...
    },
    "api": {
        ...
    }
}*/ ?>

Let me know if you need any other config.

@nodiscc nodiscc added server support installation and configuration issues labels Nov 2, 2023
@nodiscc nodiscc changed the title root_url not taken into account for template assets and routing root_url not taken into account for template assets and routing using Caddy Nov 3, 2023
@nodiscc
Copy link
Member

nodiscc commented Nov 3, 2023

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?

@moeenio
Copy link
Author

moeenio commented Nov 9, 2023

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
Copy link
Member

nodiscc commented Nov 10, 2023

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
Copy link
Member

nodiscc commented Mar 10, 2024

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

@EwenKorr

This comment was marked as off-topic.

@EwenKorr

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback needed server support installation and configuration issues
Projects
None yet
Development

No branches or pull requests

3 participants