Update to topic: V2 - Caddy Config Help

Just an update to this topic, since it’s closed:

I banged my had against the wall for quite some time, so I thought it’d be useful for someone with similar issues.

I was having problems with the SERVER_PORT variable not being forwarded because I was using a too simple implementation of Caddyfile in V2.

User WeidiDeng did a more expanded form of the Caddyfile sintax that works. However, the syntax used in his post is no longer valid.

If someone has the same problem, here’s an updated caddyfile compliant with the stable build of v2:

domain.com:8445 {
  #tls internal
  encode gzip
  root * /path/main_site
# Previous
# matcher indexFiles {
    
# Compliant with the table build of v2    
@indexFiles {
    not {
        path */
    }
    file {
        try_files {path}/index.php
    }
}
# Previous
# rewrite match:indexFiles {path}/ # No redirect required

# Compliant with the table build of v2    
rewrite @indexFiles {path}/ # No redirect required

# internally rewrite directory URIs to index.php files
# try_files {path} {path}/ /index.php/{uri} # Last part is the problem
# THis one works for Laravel
try_files {path} {path}/ /index.php/{query} # Last part is the problem

# proxy any requests for PHP files to backend via FastCGI
#matcher phpFiles {
@phpFiles {
    path *.php
}
# reverse_proxy match:phpFiles php-fpm:9000 {
reverse_proxy @phpFiles php-fpm:9000 {
    transport fastcgi {
        split .php
    }
}

  file_server
}

You’re welcome ^^

For those wondering what changed, the “matcher:” directive became an at symbol. (@)

Turns out I was looking at erroneous data. Well, the server_port behavior is supposed to be fixed in next version of Caddy:

I actually managed to do it with V2.0.0 :slight_smile:

The env directory for transport is still valid :grimacing:

So, the reverse proxy block can look like this:

reverse_proxy @phpFiles php-fpm:9000 {
transport fastcgi {
    split .php
    env SERVER_PORT "80"
}

Now XDebug works like a charm :relieved:

Can’t you just do this?

php_fastcgi php-fpm:9000 {
	env SERVER_PORT "80"
}

Edit: Wait nevermind, that’s only possible in Caddy v2.1. Well, beta 1 is out since last week, so you could use that instead!

This functionality was added here:

1 Like

I’ll test that for sure :slight_smile:

So, what’s the roadmap to Caddy 2.1 stable? :blush:
It works like a charm. My-my! :smiley:

Great!

We don’t really have any specific roadmap in mind, we usually just tag releases when it makes sense (enough issues/PRs resolved). You can expect it to be in the next few weeks though.

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