Yeah, you’re probably right. It’s a bit tricky because the actual expanded structure in the resulting JSON depends on whether the user specifies a matcher or not.
FYI, we’re working on some improvements to php_fastcgi
so that the internal structure of it can be overridden with some options. If merged, it’ll probably only be available in v2.1
caddyserver:master
← francislavoie:php-fastcgi-options
opened 01:32AM - 11 Apr 20 UTC
The [php_fastcgi](https://caddyserver.com/docs/caddyfile/directives/php_fastcgi)… Caddyfile directive acts as a shortcut to a quite long expanded form. There are many situations where users might want to override some of the behaviour generated by the shortcut.
This change makes it possible to override some aspects of the shortcut by first reading the subdirective block once, handling any subdirectives that are relevant, and importantly, deleting the tokens as it goes. Then, it rewinds the Dispenser's cursor to the point just before so that the `reverse_proxy`'s UnmarshalCaddyfile can read it for itself. We delete as we go, because otherwise the `default:` case in `reverse_proxy` would return `d.Errf("unrecognized subdirective %s", d.Val())`.
Adds the following subdirectives:
- `split`: passthrough to the `split_path` subdirective of the `fastcgi` transport, but also affects the path matcher for the list of PHP file extensions to support
- `env`: passthrough to the `env` subdirective of the `fastcgi` transport
- `root`: passthrough to the `root` subdirective of the `fastcgi` transport
- `index`: defaults to `index.php`, controls the file that is used as a `try_files` fallback. If the value is set to `off`, it disables the path canonicalization redirect and the `try_files` rewrite altogether.
Caddyfile:
```
:8884
php_fastcgi localhost:9000 {
# some php_fastcgi-specific subdirectives
split .php .phpt
env PATH /something
root /var/somewhere
index off
# passed through to reverse_proxy (directive order doesn't matter!)
lb_policy random
}
```
JSON output:
```
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":8884"
],
"routes": [
{
"match": [
{
"path": [
"*.php",
"*.phpt"
]
}
],
"handle": [
{
"handler": "reverse_proxy",
"load_balancing": {
"selection_policy": {
"policy": "random"
}
},
"transport": {
"env": {
"PATH": "/something"
},
"protocol": "fastcgi",
"root": "/var/somewhere",
"split_path": [
".php",
".phpt"
]
},
"upstreams": [
{
"dial": "localhost:9000"
}
]
}
]
}
]
}
}
}
}
}
```
1 Like
matt
(Matt Holt)
April 14, 2020, 2:31pm
22
That’s actually a pretty good idea. I guess that’s technically more accurate than leaving them as normal/separate directives.
Good thing I saw this post. I thought I was alone. My issue was that I did not put the file_server option. So in the beginning it looked like this
https://thedeveloper.club {
tls emai@gmail.com
encode zstd gzip
root * /var/www/
@cachedFiles {
path *.jpg *.jpeg *.png *.gif *.ico *.js *.css *.html *.svg *.ttf *.webp *.woff2 *.woff
}
try_files {path} {path}/index.php
header @cachedFiles Cache-Control “public, max-age=604800, must-revalidate”
php_fastcgi localhost:9000
}
but after updating it it looked like this
https://thedeveloper.club {
tls emai@gmail.com
encode zstd gzip
root * /var/www/
@cachedFiles {
path *.jpg *.jpeg *.png *.gif *.ico *.js *.css *.html *.svg *.ttf *.webp *.woff2 *.woff
}
try_files {path} {path}/index.php
file_server
header @cachedFiles Cache-Control “public, max-age=604800, must-revalidate”
php_fastcgi localhost:9000
}
Now it works. I also learned that if the file_server is there and I add the slah in php_fastcgi it will show the whole code, including PHP code. Like so:
php_fastcgi / localhost:9000
Am just learning the new version 2 format. Having fun.
luisalvarado:
Now it works. I also learned that if the file_server is there and I add the slah in php_fastcgi it will show the whole code, including PHP code. Like so:
php_fastcgi / localhost:9000
Am just learning the new version 2 format. Having fun.
That’s because in v2, path matchers are exact-match. Omitting the /
makes it default to *
. If you put just /
then it only matches requests to /
. Typically you append *
to the end of the path matcher. For example /api*
2 Likes
Thank you Francis, this opens up a whole new world of possibilities. A new fantastic point of view, where the system will not tell you No, or where to go, or deny what we could be dreaming.
4 Likes
system
(system)
Closed
July 14, 2020, 3:45pm
26
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.