How to config my Caddyfile

1. Output of caddy version:

v2.6.2 h1:wKoFIxpmOJLGl3QXoo6PNbYvGW4xLEgo32GPBEjWL8o=

2. How I run Caddy:

www.tigerice.cn {
        
        route /merchant/* {
                
                uri strip_prefix  /merchant
                
                file_server {
                        
                     root /opt/twomicro_v2/web/merchant
                     
                     browse

                     disable_canonical_uris 
                
                }
        } 

        file_server * {
                root /var/www/html
        }

        reverse_proxy /nacos  {
                to http://127.0.0.1:8848
        }

}

a. System environment:

CentOS7

b. Command:

systemctl start caddy

c. Service/unit/compose file:

# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddy config:

www.tigerice.cn {

	route /merchant/* {
		uri strip_prefix /merchant

		file_server {
			root /opt/twomicro_v2/web/merchant

			browse

			disable_canonical_uris
		}
	}

	file_server * {
		root /var/www/html
	}

	reverse_proxy /nacos {
		to http://127.0.0.1:8848
	}

}

3. The problem I’m having:

how to change nginx proxy config to caddy

nginx proxy

          location /nacos {              
              proxy_pass http://127.0.0.1:8848/nacos;
          }

caddy proxy

	reverse_proxy /nacos {
		to http://127.0.0.1:8848
	}

curl -v https://www.tigerice.cn/nacos/

reverse_proxy

curl -v https://www.tigerice.cn:8848/nacos/

how to config!

4. Error messages and/or full log output:

Paste logs/commands/output here.
USE THE PREVIEW PANE TO MAKE SURE IT LOOKS NICELY FORMATTED.

5. What I already tried:

6. Links to relevant resources:

path matcher are an exact match.
So the /nacos in reverse_proxy /nacos will only ever match /nacos but not /nacos/ or /nacos/example.

Change it to reverse_proxy /nacos* or use a named matcher like so:

@nacos path /nacos /nacos*
reverse_proxy @nacos {
	to http://127.0.0.1:8848
}
2 Likes

thank you,bro, i will try

FYI, /nacos* also matches /nacos so it can be simplified to just this:

reverse_proxy /nacos* 127.0.0.1:8848

Don’t need to use to either, the upstream can be inlined.

3 Likes

thanks, i got it!

This topic was automatically closed after 30 days. New replies are no longer allowed.