Caddy: fastcgi with more than 1 file extension causes error

Created on 5 Apr 2017  路  30Comments  路  Source: caddyserver/caddy

1. What version of Caddy are you running (caddy -version)?

windows7 & FreeBSD armv7
0.9.5

2. What are you trying to do?

add filetype .phtml on the fastcgi ext

3. What is your entire Caddyfile?

fastcgi / 127.0.0.1:9000 php {
ext .php .phtml
}

4. How did you run Caddy (give the full command and describe the execution environment)?

service caddy start

5. Please paste any relevant HTTP request(s) here.

php is runing;
but phtml not,only show source code

bug

All 30 comments

I've been able to reproduce this.

@abiosoft Thanks for checking it out! Can I assign you to this?

Yeah you can.

Hey @abiosoft do you want any help getting this resolved?

Could there be any situation where ext and split can be different ?
Since Caddy isn't splitting by regex, I don't think that is ever gonna happen.

@abiosoft Great question. I'm not sure off-hand. Maybe someone else would have an example?

If we find that split is never different than ext, then I think we might as well remove the arguments from split so that it just inherits them from ext if any.

There is an example in the docs that uses split without ext being set:

fastcgi / 127.0.0.1:9001 {
    split .html
}

But I think that was just meant as a configuration example and not a real-world usable case.

I propose we simply remove/depreciate split while fixing this. This is the main blocker.

If that sounds fine, I can go ahead and finalize this.

@abiosoft Great -- let's get a PR going and we can poll people to give their input. We should be "gentle" in this case by showing a warning when using the split subdirective, which is being deprecated, and if they need it, they should post an issue (link to Caddy issues). That way, they'll know to get in touch with us.

We can always add the split feature later if needed.

@abiosoft I thought the split feature is there for separating the PATH_INFO and is unrelated to accepting cgi requests for specific file extensions.

RFC3875: CGI Spec 1.1: Section 4.1.5

Just took a quick look.. seems as though the ext fastcgi directive doesn't support multiple extensions.

https://github.com/mholt/caddy/blob/master/caddyhttp/fastcgi/fastcgi.go#L84
https://github.com/mholt/caddy/blob/master/caddyhttp/fastcgi/setup.go#L95

Yes but in Caddy's case, I am yet to see when it is not same value as ext. e.g. in the php preset https://github.com/mholt/caddy/blob/master/caddyhttp/fastcgi/setup.go#L199

@abiosoft I thought the split feature is there for separating the PATH_INFO and is unrelated to accepting cgi requests for specific file extensions.

Yes, which is why it breaks when more than one is specified.

Just took a quick look.. seems as though the ext fastcgi directive doesn't support multiple extensions.

@abiosoft In the past (on other web servers) I have used these separately. Extensions to detect and serve content and PATH_INFO to provide information on what to serve. So you have one say phpfile that serves lots of content. Another example is using extension .html having it processed as php but having the .html extension kept in PATH_INFO.

My remark was mainly aimed at the initial issue opened by @iscraft that he is trying to use multiple extensions and its it not working. caddy/issues/1564#issue-219613123 I thought that was the bug that was required to be fixed. The confusion might be caused because of the difference with the ext plugin vs. the fastcgi plugin. Ref: https://caddyserver.com/docs/ext

@slightfoot

In the past (on other web servers) I have used these separately. Extensions to detect and serve content and PATH_INFO to provide information on what to serve. So you have one say phpfile that serves lots of content.

Can you share those lines of config so we can see how they're being used separately?

I realize that the separation of these two is slightly tangential, and it's probably best to focus on the original issue here; but they are related, and if one is blocking the other, let's knock out both (if needed).

The direct fix to this issue is allow specifying multiple ext and split. Which is quite straightforward though a bit challenging on how to represent it in the config since an ext need to be attached to a split (I think).

ext .php .html
split .php .html

Just wondering why we need to specify same thing in two places.

This is a good point. I'd be interested to know @slightfoot's use case where they are different.

I tested this issue and I reproduced it with Caddy 0.10.11 on Windows 7 x64.

I tested a workaround to make both work on my platform. I think it would work on other platforms too but it may need extra testing.

You could have two fastcgi directives.

Here's a minimal example on Windows:

on startup C:\caddysites\php\php-cgi.exe -b 6545 &
fastcgi / 127.0.0.1:6545 {
    ext .php
}
fastcgi / 127.0.0.1:6545 {
    ext .phtml
}

I tested a .php and .phtml page and both worked perfectly.

Is it a viable solution without having to change the code?

Maybe this limitation could be mentioned in the docs or a similar example could be added? https://caddyserver.com/docs/fastcgi

I think I'll go ahead with the fix I had in mind back then which is to remove split and properly support multiple extensions. I haven't seen any specific case where ext and split have been different.

@abiosoft Do you know if this was ever fixed? Can we close this issue?

@tobya no, it hasn't been fixed. Since there has been no objections all this while, I'll go ahead with my suggestion by removing split in favour of ext.

I should have time for this within the next week.

@abiosoft if split is removed, will the code still split eg. Given the url

https://example.com/pages/myfile.php/userid/docid/test

after the change will $_SERVER['PATH_INFO'] still contain /userid/docid/test ? Which is what it should contain at the moment.

If so I think we could go ahead, although I do like @magikstm workaround also.

If this is not the case we need to decide if we are happy breaking functionality.

@tobya Yes it will.

after the change will $_SERVER['PATH_INFO'] still contain /userid/docid/test ? Which is what it should contain at the moment.

Can anyone verify whether this is still an issue with Caddy 2? (Caddy 2 is currently in beta on the v2 branch. See its readme and the wiki for full documentation.)

I will try to test this.

Thanks as always, Toby!

I've looked at this in V2 and cant see how more than one extension can be specified, so this is still outstanding. It seems necessary to be able to specify multiple extensions in these 2 places

"handle": [ { "handler": "reverse_proxy", "transport": { "protocol": "fastcgi", "split_path": ".phtml" }, "upstreams": [ { "dial": "localhost:4344" } ] } ],
and (although I presume I can already here)
"match": [ { "path": [ "*.phtml" ] }

I'm not even sure how you would split on more than one substring.

Well we just need to allow multiple file ext for php files
eg

php, phtml, html

whatever someone wants really. Then when a file is requested matching any of the exts we need to send file request to php and split on that extention

So how about if split_path was a placeholder: {http.request.uri.ext} ? (Will have to make it, I think)

v2 now supports trying multiple substrings for splitting the path, so I think this is fixed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whs picture whs  路  3Comments

treviser picture treviser  路  3Comments

PhilmacFLy picture PhilmacFLy  路  3Comments

mikolysz picture mikolysz  路  3Comments

dafanasiev picture dafanasiev  路  3Comments