Soft fork for a caddy reverse template for railway
1# global options
2{
3 admin off # theres no need for the admin api in railway's environment
4 persist_config off # storage isn't persistent anyway
5 auto_https off # railway handles https for us, this could in some cases cause issues if left enabled
6 # runtime logs
7 log {
8 format json # set runtime log format to json mode
9 }
10 # server options
11 servers {
12 trusted_proxies static private_ranges # trust railway's proxy
13 }
14}
15
16(lb_settings) {
17 lb_policy round_robin
18 lb_retries 100
19 lb_try_duration 10s
20 lb_try_interval 250ms
21}
22
23(passive_health_checks) {
24 fail_duration 60s
25 max_fails 300
26 unhealthy_latency 5s
27 unhealthy_request_count 200
28}
29
30# site block, listens on the $PORT environment variable, automatically assigned by railway
31:{$PORT} {
32 # access logs
33 log {
34 format json # set access log format to json mode
35 }
36
37 # proxy all requests for /* to the frontend, configure these variables in the service settings
38 reverse_proxy {
39 # for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
40 dynamic a {
41 name {$FRONTEND_DOMAIN}
42 port {$FRONTEND_PORT}
43 refresh 1s
44 dial_timeout 30s
45 versions ipv4 ipv6
46 }
47
48 # configure load balancing settings
49 import lb_settings
50
51 # configure passive health checks
52 import passive_health_checks
53
54 # sets the Host header to the header to the dynamic name and port options
55 header_up Host {upstream_hostport}
56 }
57
58 # the handle_path directive WILL strip /api/ from the path before proxying
59 # use `handle` instead of `handle_path` if you dont want to strip the /api/ path
60 # this is needed if your backend's api routes don't start with /api/
61 # change paths as needed
62 handle {$BACKEND_PATH:/api}/* {
63 # the /api/ prefix WILL be stripped from the uri sent to the proxy host
64 #
65 # proxy all requests for /api/* to the backend, configure this variable in the service settings
66 reverse_proxy {
67 # for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
68 dynamic a {
69 name {$BACKEND_DOMAIN}
70 port {$BACKEND_PORT}
71 refresh 1s
72 dial_timeout 30s
73 versions ipv4 ipv6
74 }
75
76 # configure load balancing settings
77 import lb_settings
78
79 # configure passive health checks
80 import passive_health_checks
81
82 # sets the Host header to the header to the dynamic name and port options
83 header_up Host {upstream_hostport}
84 }
85 }
86}