Skip to content

Instantly share code, notes, and snippets.

@twnaing
Created July 3, 2020 08:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twnaing/4012b8817d191bc15ee5853e513c2689 to your computer and use it in GitHub Desktop.
Save twnaing/4012b8817d191bc15ee5853e513c2689 to your computer and use it in GitHub Desktop.
Caddyfile v2 for Ruby on Rails application
# save Caddyfile in rails app root folder
# run rails server with port 4000 in one terminal
$ bundel exec rails server -p 4000 -b 127.0.0.1
# run caddy in another terminal
CADDY_HOST=localhost CADDY_PORT=3000 CADDY_BACKEND_PORT=4000 caddy run -config Caddyfile
http://{$CADDY_HOST}:{$CADDY_PORT} {
root * ./public
@notStatic {
not {
file {
try_files {path}
}
}
}
reverse_proxy @notStatic {
to localhost:{$CADDY_BACKEND_PORT}
header_up X-Real-IP {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up Access-Control-Allow-Origin *
header_up Access-Control-Allow-Credentials true
header_up Access-Control-Allow-Headers Cache-Control,Content-Type
transport http {
read_buffer 8192
}
}
file_server
}
@twnaing
Copy link
Author

twnaing commented Jul 3, 2020

Adapt most of the config from this URL

@twnaing
Copy link
Author

twnaing commented Jul 3, 2020

for Caddyfile v1, check this out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment