71 lines
2.4 KiB
Plaintext
71 lines
2.4 KiB
Plaintext
nano /etc/caddy/Caddyfile
|
|
|
|
domain2.com {
|
|
reverse_proxy 0.0.0.0:
|
|
}
|
|
yourdomain.com {
|
|
@allowed_origins {
|
|
origin_regexp ^(https?://(app\.example\.com|localhost:3000|dev\.site\.org))$
|
|
}
|
|
|
|
header @allowed_origins Access-Control-Allow-Origin "{http.request.header.origin}"
|
|
header @allowed_origins Access-Control-Allow-Methods "GET, POST, OPTIONS"
|
|
header @allowed_origins Access-Control-Allow-Credentials "true"
|
|
|
|
reverse_proxy localhost:8055
|
|
}
|
|
yourdomain.com {
|
|
# Handle OPTIONS preflight requests
|
|
@preflight method OPTIONS
|
|
|
|
# Workaround for older Caddy versions (no 'origin' matcher)
|
|
@cors_origin {
|
|
header Origin ^(http://localhost:3000|https://localhost:3000|https://.*\.example\.com|https://your-production-domain\.com)$
|
|
}
|
|
|
|
# CORS headers for actual requests
|
|
header @cors_origin Access-Control-Allow-Origin "{http.request.header.origin}"
|
|
header @cors_origin Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
|
|
header @cors_origin Access-Control-Allow-Headers "*"
|
|
header @cors_origin Access-Control-Allow-Credentials "true"
|
|
header @cors_origin Vary Origin
|
|
|
|
# Special handling for preflight requests
|
|
header @preflight Access-Control-Allow-Origin "{http.request.header.origin}"
|
|
header @preflight Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
|
|
header @preflight Access-Control-Allow-Headers "*"
|
|
header @preflight Access-Control-Max-Age "3600"
|
|
|
|
# Proxy to your backend
|
|
reverse_proxy localhost:8055
|
|
|
|
# Respond to OPTIONS requests immediately
|
|
respond @preflight 204
|
|
}
|
|
|
|
# The Caddyfile is an easy way to configure your Caddy web server.
|
|
#
|
|
# Unless the file starts with a global options block, the first
|
|
# uncommented line is always the address of your site.
|
|
#
|
|
# To use your own domain name (with automatic HTTPS), first make
|
|
# sure your domain's A/AAAA DNS records are properly pointed to
|
|
# this machine's public IP, then replace ":80" below with your
|
|
# domain name.
|
|
|
|
:80 {
|
|
# Set this path to your site's directory.
|
|
root * /usr/share/caddy
|
|
|
|
# Enable the static file server.
|
|
file_server
|
|
|
|
# Another common task is to set up a reverse proxy:
|
|
# reverse_proxy localhost:8080
|
|
|
|
# Or serve a PHP site through php-fpm:
|
|
# php_fastcgi localhost:9000
|
|
}
|
|
|
|
# Refer to the Caddy docs for more information:
|
|
# https://caddyserver.com/docs/caddyfile |