forked from railwayapp-templates/caddy-reverse-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaddyfile
128 lines (110 loc) · 3.09 KB
/
Caddyfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# global options
{
admin off # theres no need for the admin api in railway's environment
persist_config off # storage isn't persistent anyway
auto_https off # railway handles https for us, this could in some cases cause issues if left enabled
# runtime logs
log {
format json # set runtime log format to json mode
}
# server options
servers {
trusted_proxies static private_ranges # trust railway's proxy
}
order s3proxy last
}
(lb_settings) {
lb_policy round_robin
lb_retries 100
lb_try_duration 10s
lb_try_interval 250ms
}
(passive_health_checks) {
fail_duration 60s
max_fails 300
unhealthy_latency 5s
unhealthy_request_count 200
}
# site block, listens on the $PORT environment variable, automatically assigned by railway
:{$PORT} {
# access logs
log {
format json # set access log format to json mode
}
# proxy all requests for /* to the frontend, configure these variables in the service settings
reverse_proxy {
# for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
dynamic a {
name {$FRONTEND_DOMAIN}
port {$FRONTEND_PORT}
refresh 1s
dial_timeout 30s
versions ipv4 ipv6
}
# configure load balancing settings
import lb_settings
# configure passive health checks
import passive_health_checks
# sets the Host header to the header to the dynamic name and port options
header_up Host {upstream_hostport}
}
redir /u /u/ 301
handle_path /u* {
reverse_proxy {
# for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
dynamic a {
name {$DASHBOARD_DOMAIN}
port {$DASHBOARD_PORT}
refresh 1s
dial_timeout 30s
versions ipv4 ipv6
}
# configure load balancing settings
import lb_settings
# configure passive health checks
import passive_health_checks
# sets the Host header to the header to the dynamic name and port options
header_up Host {upstream_hostport}
}
}
handle /api/* {
# proxy all requests for /api/* to the backend, configure this variable in the service settings
reverse_proxy {
# for private networking replicas are exposed as multiple dns results, use those dns results as the upstreams
dynamic a {
name {$BACKEND_DOMAIN}
port {$BACKEND_PORT}
refresh 1s
dial_timeout 30s
versions ipv4 ipv6
}
# configure load balancing settings
import lb_settings
# configure passive health checks
import passive_health_checks
# sets the Host header to the header to the dynamic name and port options
header_up Host {upstream_hostport}
}
}
handle_path /ws {
rewrite * /{$STAGE}{uri}
reverse_proxy {$CHAT_API_URL} {
header_up Host {upstream_hostport}
}
}
# location /boticons {
# alias /home/ubuntu/s3/prod_customize;
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto https;
# }
route /boticons/icons/* {
uri strip_prefix /boticons
s3proxy {
bucket {$S3_BUCKET}
region {$S3_REGION}
force_path_style
}
}
}