Caddy doesn't show images and root isnt working for some reason

I saw a post about this but the answer wasn’t about enabling, more about converting to URI which doesn’t work for me. Anyway this is my Caddy file

exploresrpska.com {
    root /shop/static/assets
    encode gzip
    file_server
    reverse_proxy localhost:50100
}


When i start this, i get an error:

Error: adapting config using caddyfile: parsing caddyfile tokens for 'root': Caddyfile:2 
- Error during parsing: Wrong argument count or unexpected line ending after 'root', impo
rt chain: ['']
Error: caddy process exited with error: exit status 1

This is an project and i already made a lot of images so i would like just to access them from my server files

Since the first argument to root is a path, you need to specify * as the matcher otherwise the parser gets confused and thinks you’re specifying a path matcher.

root * /shop/static/assets

But also, it doesn’t make sense to use both reverse_proxy and file_server in a config like that without also using request matchers to split which requests go where.

Without more details of how your app works, I can’t suggest anything specific.

Please fill out the help topic template, as per the forum rules.

Hi, sorry for not filling like template, been posting 3 times here today. Anyway i did what u said earlier, but i realized its a permission problem. I cant change permission of my assets folder.

i will post a new post with following template.

Hi everyone,

1. The problem I’m having:

I have Ubuntu server on LightSail with caddy trying to host my flask web app. Web app works fine, but the images are not loading at all. Images are there, I can see them in directory, and they are connected properly in HTML and CSS. I realized its a permission problem. I tried to change permission and ownership, maybe I did because I cant access directory at all. I tried chaging it again with command sudo chown -R caddy:caddy assets it doenst do anyting. When i tried ls -l assets it shows me this:

ls: cannot access 'assets/green.png': Permission denied
ls: cannot access 'assets/1.jpg': Permission denied
ls: cannot access 'assets/Logo.png': Permission denied
ls: cannot access 'assets/Untitled-1.jpg': Permission denied
ls: cannot access 'assets/restaurant-with-christmas-decorations-2022-11-15-18-02-21-utc.j
pg': Permission denied
ls: cannot access 'assets/background1.jpg': Permission denied
ls: cannot access 'assets/google_map_logo.png': Permission denied
ls: cannot access 'assets/banjaluka.jpg': Permission denied
ls: cannot access 'assets/LOGO_EPSwhite.png': Permission denied
ls: cannot access 'assets/LOGO_EPS.png': Permission denied
ls: cannot access 'assets/logopowered.png': Permission denied
ls: cannot access 'assets/URI.txt': Permission denied
ls: cannot access 'assets/logo1.png': Permission denied
ls: cannot access 'assets/Watercolor pian.jpg': Permission denied
ls: cannot access 'assets/kkl.jpg': Permission denied
ls: cannot access 'assets/2.jpg': Permission denied
ls: cannot access 'assets/Watercolor pian.png': Permission denied
ls: cannot access 'assets/google_map.png': Permission denied
total 0
-????????? ? ? ? ?            ?  1.jpg
-????????? ? ? ? ?            ?  2.jpg
-????????? ? ? ? ?            ?  LOGO_EPS.png
-????????? ? ? ? ?            ?  LOGO_EPSwhite.png
-????????? ? ? ? ?            ?  Logo.png
-????????? ? ? ? ?            ?  URI.txt
-????????? ? ? ? ?            ?  Untitled-1.jpg
-????????? ? ? ? ?            ? 'Watercolor pian.jpg'
-????????? ? ? ? ?            ? 'Watercolor pian.png'
-????????? ? ? ? ?            ?  background1.jpg
-????????? ? ? ? ?            ?  banjaluka.jpg
-????????? ? ? ? ?            ?  google_map.png
-????????? ? ? ? ?            ?  google_map_logo.png
-????????? ? ? ? ?            ?  green.png
-????????? ? ? ? ?            ?  kkl.jpg
-????????? ? ? ? ?            ?  logo1.png
-????????? ? ? ? ?            ?  logopowered.png
-????????? ? ? ? ?            ?  restaurant-with-christmas-decorations-2022-11-15-18-02-2
1-utc.jpg

If anyone wonder about user and group stuff, this is output of caddy id

uid=998(caddy) gid=999(caddy) groups=999(caddy),33(www-data)

I don’t have much knowledge about user and group because am new to all of this.

2. Error messages and/or full log output:

Here is output of journalctl -u caddy -n 50

Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: NOTIFY_SOCKET=/run/systemd/notify
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: HOME=/var/lib/caddy
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: LOGNAME=caddy
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: USER=caddy
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: INVOCATION_ID=2df7836501f34be0b89b80af6acf0c83
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: JOURNAL_STREAM=8:26292
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: SYSTEMD_EXEC_PID=2445
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.395149,"msg":"using provided configuration","config_file":>
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3964388,"logger":"admin","msg":"admin endpoint started","a>
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"warn","ts":1695312321.3965304,"logger":"http.auto_https","msg":"server is listen>
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3967326,"logger":"http.log","msg":"server running","name":>
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3969228,"msg":"autosaved config (load with --resume flag)">
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3969712,"msg":"serving initial configuration"}
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3970883,"logger":"tls.cache.maintenance","msg":"started ba>
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3971097,"logger":"tls","msg":"cleaning storage unit","desc>
Sep 21 16:05:21 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312321.3971236,"logger":"tls","msg":"finished cleaning storage un>
Sep 21 16:05:21 ip-172-26-8-229 systemd[1]: Started Caddy.
Sep 21 16:05:28 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312328.299067,"logger":"admin.api","msg":"received request","meth>
Sep 21 16:05:28 ip-172-26-8-229 caddy[2445]: {"level":"warn","ts":1695312328.29927,"logger":"admin.api","msg":"exiting; byeee!! "}
Sep 21 16:05:28 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312328.2992837,"logger":"http","msg":"servers shutting down with >
Sep 21 16:05:28 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312328.2995238,"logger":"admin","msg":"stopped previous server",">
Sep 21 16:05:28 ip-172-26-8-229 caddy[2445]: {"level":"info","ts":1695312328.2995343,"logger":"admin.api","msg":"shutdown complete","ex>
Sep 21 16:05:28 ip-172-26-8-229 systemd[1]: caddy.service: Deactivated successfully.
Sep 21 16:13:47 ip-172-26-8-229 systemd[1]: Starting Caddy...
Sep 21 16:13:47 ip-172-26-8-229 caddy[2548]: caddy.HomeDir=/var/lib/caddy
Sep 21 16:13:47 ip-172-26-8-229 caddy[2548]: caddy.AppDataDir=/var/lib/caddy/.local/share/caddy
Sep 21 16:13:47 ip-172-26-8-229 caddy[2548]: caddy.AppConfigDir=/var/lib/caddy/.config/caddy
Sep 21 16:13:47 ip-172-26-8-229 caddy[2548]: caddy.ConfigAutosavePath=/var/lib/caddy/.config/caddy/autosave.json
Sep 21 16:13:47 ip-172-26-8-229 caddy[2548]: caddy.Version=v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=
Sep 21 16:13:47 ip-172-26-8-229 caddy[2548]: runtime.GOOS=linux

Hope this helps because i dont understand a thing here :smiley:

3. Caddy version:

v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=

4. How I installed and ran Caddy:

a. System environment:

No LSB modules are available.
Distributor ID:Ubuntu
Description:Ubuntu 22.04.1 LTS
Release:22.04
Codename:jammy

b. Command:

Process of starting caddy:

source env/bin/activate
cd Turizam
caddy stop
sudo caddy start
python run.py

d. My complete Caddy config:

On previous post francislavoie told me that i dont really need file_server and reverse_proxy. I just copied file server dont know what does it even do :smiley: if it is ok to delete it i will.

exploresrpska.com {
    root * /shop/static/assets
    file_server
    reverse_proxy localhost:50100
}

5. Links to relevant resources:

Heres link of tutorial that i followed, maybe helps, dont know.

What file_server does is it literally in its name. It serves files from disk.

If your upstream app handles serving files already, then you don’t need file_server at all and you can keep only reverse_proxy.

Like I said earlier, it doesn’t make sense to use both directives at the same time without request matchers. See Request matchers (Caddyfile) — Caddy Documentation, you need to configure Caddy to tell it which requests should use file_server and which should use reverse_proxy. Often that’s done by matching the request path.

But this is all very specific to the application you’re running, and I can’t answer what’s needed since I don’t understand the application you wrote.

Where are these files stored? What’s the full path? The permissions on parent directories matter too, if you do actually need file_server, the caddy user would need the executable permission on every directory parent to your assets directory to be able to see it.

That makes sense, because you set the user/group to caddy and you ran ls as your current user which now no longer has permission to read those files.

Fixed it.
It was ubuntu who denied permission.