caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
56.97k stars 3.99k forks source link

add mime config with caddy or php-fpm #4546

Closed vay3t closed 2 years ago

vay3t commented 2 years ago

This is question and suggestion. Is there any way to implement this AddType rule originally seen in apache called mime_mod? If not, is there any suggestion to implement this as an extension to Caddy? (some guide on how to do it correctly. I know that there is an API in GO to create modules).

What exactly I need is to implement the following rule: "AddType application/x-httpd-php .html"

mholt commented 2 years ago

That basically sets the Content-Type header, right?

So wouldn't you just need:

@html path *.html
header @html Content-Type application/x-httpd-php

Or something like that?

francislavoie commented 2 years ago

Go pulls the mime types from your system's mailcap file locations, see if you can add any mappings in there. Quick google search brought me to http://manpages.ubuntu.com/manpages/bionic/man8/update-mime.8.html, which may be relevant depending on your OS.

I don't think this is something we'd need in Caddy's core, you could possibly write a plugin to add overrides using the https://pkg.go.dev/mime stdlib package. You can find the docs for Caddy plugins here: https://caddyserver.com/docs/extending-caddy

ghost commented 2 years ago

In case any one is interested in using their own mime.types file with Caddy, I've uploaded https://github.com/xnaas/webserver/blob/master/caddy/mime.types. Per the comments, the file is based on https://github.com/h5bp/server-configs-nginx/blob/a9617688fc921e728d5dcd044db9327aa50ede79/mime.types, I've just modified it to make the golang mime library happy.

eddyizm commented 6 months ago

Just running into this issue again but given the work around

@html path *.html
header @html Content-Type application/x-httpd-php

where do I add this in a file server ? Does the path go elsewhere in the file, as this does not seem to do the trick and instead is returning content type text/html

        handle_path /media/* {
          @png path *.png
          header @png Content-Type image/png

          root * /home/<redacted>/media/
          file_server
        }

@ghostwheel42 I'd love to see how your list is implemented in a caddy file!

mholt commented 6 months ago

@eddyizm What is complete output (and the command) of a curl -v request that gives back HTML instead of PNG?

eddyizm commented 6 months ago

@mholt I tried a slew of things and gave up. I believe this is not an issue with caddy but an issue with my django application/template. Thanks for the reply!

mholt commented 6 months ago

Ok. Thanks for letting us know!

eddyizm commented 6 months ago

No problem, trying to work out all my issues, hoping to switch all my servers to Caddy, it's really amazing!