caddy_test.go 881 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package caddy_test
  2. import (
  3. "net/http"
  4. "testing"
  5. "github.com/caddyserver/caddy/v2/caddytest"
  6. )
  7. func TestPHP(t *testing.T) {
  8. tester := caddytest.NewTester(t)
  9. tester.InitServer(`
  10. {
  11. http_port 9080
  12. https_port 9443
  13. }
  14. localhost:9080 {
  15. route {
  16. root * {env.PWD}/../testdata
  17. # Add trailing slash for directory requests
  18. @canonicalPath {
  19. file {path}/index.php
  20. not path */
  21. }
  22. redir @canonicalPath {path}/ 308
  23. # If the requested file does not exist, try index files
  24. @indexFiles file {
  25. try_files {path} {path}/index.php index.php
  26. split_path .php
  27. }
  28. rewrite @indexFiles {http.matchers.file.relative}
  29. # Handle PHP files with FrankenPHP
  30. @phpFiles path *.php
  31. php @phpFiles
  32. respond 404
  33. }
  34. }
  35. `, "caddyfile")
  36. tester.AssertGetResponse("http://localhost:9080", http.StatusOK, "I am by birth a Genevese")
  37. }