How to write re-write rules for symfony application running using caddy

1. Caddy version (v2.4.0):

d. My complete Caddyfile or JSON config:

caddyt.tamilchatz.com {
root * /www/wwwroot/caddytest/tamilchat/public
php_fastcgi unix//run/php/php8.0-fpm.sock
file_server
tls admin@tamilchatz.com {
protocols tls1.2 tls1.3
}
}
test.caddyt.tamilchatz.com {
file_server
        route {
          mercure {
        	transport_url local://local
                publisher_jwt atestingjwtkeygoesinheres
                subscriber_jwt atestingjwtkeygoesinheres
        publish_origins *
                cors_origins https://caddyt.tamilchatz.com
                anonymous
                subscriptions {
                $MERCURE_EXTRA_DIRECTIVES
                }
          }
          respond /healthz 200
          respond "Not Found" 404
        }
}


3. The problem I’m having:

In nginx i used to have this re-write code to make symfony application load using php. But through caddy, i have no idea how to do it. Help me out to sort this out.

Website gives “500 Error”, check here >> https://caddyt.tamilchatz.com

Here is the NGINX code i use.

try_files $uri @rewriteapp;
  location @rewriteapp {
    rewrite ^(.*)$ /index.php/$1 last;
  }
  rewrite ^/index.php?(.*)$ /$1 permanent;

5. What I already tried:

I have tried this code

rewrite {
  to {path} {path}/ /index.php/{path}
}

But i end up getting this error while starting caddy.

run: adapting config using caddyfile: parsing caddyfile tokens for 'rewrite': /etc/caddy/Caddyfile:4 - Error during parsing: Wrong argument count or unexpected line ending after 'rewrite'

6. Links to relevant resources:

Remove this, it’s not useful. Those are already the defaults. Having this there will only make it harder for future versions of Caddy to upgrade you to use the latest recommended security defaults (say for example tls 1.4 is released, you would need to update your config to make that work, whereas if you remove it, you don’t need to touch anything and it will work seamlessly out of the box).

Check your PHP app’s logs. You must have misconfigured your application.

The php_fastcgi directive does the appropriate rewrites automatically. That logic is built-in. See the expanded form to get an idea of what it’s a shortcut for:

That’s invalid syntax, it’s from Caddy v1. Please read the official documentation, don’t look at old articles to help you.

2 Likes

True, i had to run application using dev mode to figure out what went wrong. Its some directory permission error. Anyway thanks for the help.

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